我有一份上学的工作,我有这张桌子(不完整,我简化了):
email region card quantidade
-------------- ---------- ----------- ----------
dummyEmail_1@box.net EU Flamestrike 2
dummyEmail_1@box.net EU Fireball 2
dummyEmail_1@box.net EU Polymorph 3
dummyEmail_1@box.net EU Water Eleme 6
dummyEmail_1@box.net EU Arcane Expl 3
dummyEmail_1@box.net EU Frostbolt 2
dummyEmail_1@box.net EU Arcane Miss 8
dummyEmail_1@box.net EU Mirror Imag 2
dummyEmail_1@box.net EU Archamage A 1
dummyEmail_1@box.net EU Pyroblast 2
dummyEmail_1@box.net US Pyroblast 1
dummyEmail_1@box.net EU Kirin Tor M 3
dummyEmail_1@box.net EU Goblin Blas 2
dummyEmail_1@box.net EU Unstable Po 11
dummyEmail_1@box.net EU Iron sensei 2
dummyEmail_1@box.net EU Shady Deale 2
dummyEmail_1@box.net EU Backstab 5
dummyEmail_1@box.net EU Deadly Pois 3
protoEmail_2@box.net EU Deathwing 2
protoEmail_2@box.net EU Nefarian 2
protoEmail_2@box.net EU Volcanic Dr 2
protoEmail_2@box.net EU Twilight Dr 2
protoEmail_2@box.net EU Cenarius 2
protoEmail_2@box.net EU King Krush 2
protoEmail_2@box.net EU Archmage An 2
protoEmail_2@box.net EU Tirion Ford 2
protoEmail_2@box.net EU Prophet Vel 2
protoEmail_2@box.net EU Edward VanC 2
protoEmail_2@box.net EU Al'Akir the 2
protoEmail_2@box.net EU Lord Jaraxx 2
protoEmail_2@box.net EU Grommash He 2
protoEmail_2@box.net EU Dr.Boom 2
protoEmail_2@box.net EU Mimiron's H 2
protoEmail_2@box.net EU Bolvar Ford 2
并希望从查询输出:
email card region
-------------- ------------------- ----------
protoEmail_2@box.net Grommash Hellscream EU
protoEmail_2@box.net Grommash Hellscream US
protoEmail_2@box.net Lord Jaraxxus EU
protoEmail_2@box.net Lord Jaraxxus AS
dummyEmail_2@box.net Mind Control EU
dummyEmail_2@box.net Mind Control US
dummyEmail_2@box.net Pyroblast EU
dummyEmail_2@box.net Pyroblast US
dummyEmail_2@box.net Shady Dealer EU
dummyEmail_2@box.net Shady Dealer US
dummyEmail_2@box.net Unstable Portal EU
dummyEmail_2@box.net Unstable Portal US
protoEmail_2@box.net Varian Wrynn EU
protoEmail_2@box.net Varian Wrynn US
即:我想从电子邮件和卡中选择所有重复项并显示重复卡/电子邮件的区域
我尝试了这个查询,但它给了我一个语法错误:SELECT email, card, region FROM player_card WHERE (email,card) IN (SELECT email,card FROM player_card GROUP BY email,card HAVING count(*) > 1) ORDER BY card;
表创建声明:
CREATE TABLE player_card
(email VARCHAR(30),
region VARCHAR(2) CHECK (region IN("US", "EU", "AS")),
card VARCHAR(30),
quantidade INTEGER NOT NULL,
PRIMARY KEY(email, region, card),
FOREIGN KEY(email) REFERENCES player(email) ON UPDATE CASCADE ON DELETE SET NULL,
FOREIGN KEY(region) REFERENCES player(region),
FOREIGN KEY(card) REFERENCES card(name)
);
答案 0 :(得分:0)
我可以通过使用join代替in运算符来获得结果:
SELECT p.email, p.card, p.region FROM player_card p join
(SELECT email,card, count(*) as cnt FROM player_card GROUP BY email,card) t
on p.email = t.email and p.card=t.card where t.cnt>1
ORDER BY p.card;