例如,我有一张桌子
name | ability
kevin|say
kevin|scream
nike |say
在寻找say
和scream
时,我想得到回应。参数计数可能会改变。
答案 0 :(得分:2)
您可以使用group by
和having
:
SELECT name
FROM t
WHERE ability in ('say', 'scream')
GROUP BY name
HAVING COUNT(*) = 2;
答案 1 :(得分:0)
一种方法是:
SELECT * FROM YourTableName WHERE name='kevin' AND ability IN ('say','scream');
另一种方法:
SELECT * FROM YourTableName WHERE name='kevin' AND (ability='say' || ability='scream');
祝你好运!!
答案 2 :(得分:0)
这应该有效:
SELECT name FROM tablename WHERE ability IN ('say', 'scream') GROUP BY name
或者:
SELECT DISTINCT name FROM tablename WHERE ability IN ('say', 'scream')
编辑:哦,你正在寻找具有两个能力的名字......那么你可以这样做:
SELECT DISTINCT name from tablename WHERE name IN (SELECT name FROM tablename WHERE ability = 'say') AND name IN (SELECT name FROM tablename WHERE ability = 'scream')
或者更好的是,您可以在第一个查询中添加HAVING
子句:
SELECT name FROM tablename WHERE ability IN ('say', 'scream') GROUP BY name HAVING count(*) = 2