如何返回在MySQL中具有相同列值的行让我们考虑下表-ID Score1 952 1003 884 1005 73我完全是一个SQLNoob,但是如何返回ID 2和4的分数呢?所以它应该返回100,因为它在ID 2和4中都有它的功能。
3 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
having
select scorefrom tgroup by scorehaving sum(id = 2) > 0 and -- has id = 2 sum(id = 4) > 0 -- has id = 4
having
sum(id = 2)
跃然一笑
TA贡献1826条经验 获得超6个赞
SELECT scoreFROM tWHERE id in (2, 4)HAVING COUNT(*) = 2 /* replace this with the number of IDs */
HAVING
id
慕村9548890
TA贡献1884条经验 获得超4个赞
select Scorefrom tbl awhere a.ID = 2 -- based off Score with ID = 2 --include Score only if it exists with ID 6 also and exists ( select 1 from tbl b where b.Score = a.Score and b.ID = 6 ) -- optional? ignore Score that exists with other ids as well and not exists ( select 1 from tbl c where c.Score = a.Score and c.ID not in (2, 6) )
添加回答
举报
0/150
提交
取消