0

作为一项训练练习,我正在研究一个类似于英雄联盟的虚构 SQLite 数据库,我需要执行左外连接以获取所有玩家的表,如果他们有未调用的皮肤,也'Classic'返回这些。

我目前有这个查询:

SELECT * FROM players
        LEFT OUTER JOIN (SELECT * FROM playerchampions WHERE NOT championskin = 'Classic')
            ON name = playername

它返回了我要查找的内容,但也有很多我不想要的列(玩家经验、玩家 IP、玩家 RP、玩家姓名)playerchampions。这两个表的代码如下:

CREATE TABLE players ( 
    name       TEXT    PRIMARY KEY,
    experience INTEGER,
    currencyip INTEGER,
    currencyrp INTEGER 
);
CREATE TABLE playerchampions ( 
    playername   TEXT REFERENCES players ( name ) ON UPDATE CASCADE,
    championname TEXT REFERENCES champions ( name ) ON UPDATE CASCADE,
    championskin TEXT REFERENCES skins ( skinname ) ON UPDATE CASCADE,
    PRIMARY KEY ( playername, championname, championskin ) 
);

正如我所说,查询执行,但我不能使用 SELECT player.name, playerchampions.championname, playerchampions.championskin,因为 playerchampions 列在返回时没有给出正确的表名。

我该如何解决?

4

2 回答 2

0

尝试使用别名:

SELECT p.name, c.championskin FROM players p LEFT OUTER JOIN (SELECT pc.playername playername, pc.championskin championskin FROM playerchampions pc WHERE NOT pc.championskin = 'Classic') c ON p.name = c.playername;

不确定它是否正是你需要的,但它会让你更接近......

于 2013-04-10T10:50:13.560 回答
0
SELECT * FROM players p LEFT OUTER JOIN playerchampions pc ON (p.name = pc.playername)     WHERE NOT pc.championskin = 'Classic'
于 2013-04-10T10:51:02.227 回答