例如假设我有下表
user_id, score
1,5
1,4
2,9
3,7
3,6
3,15
4,8
4,11
我想要一个返回user_id 2的查询,因为它是唯一不重复的user_id
答案 0 :(得分:7)
SELECT user_id FROM table GROUP BY(user_id) HAVING COUNT(user_id) = 1
答案 1 :(得分:1)
select user_id
from tableName
group by user_id
having count(*) = 1;
答案 2 :(得分:0)
SELECT user_id
FROM table
GROUP BY user_id
HAVING (COUNT(user_id)=1)