SELECT成员,如果level为2但不是4或5,其中成员等于1234
id | member | level
1 | 1234 | 2
2 | 1234 | 4
3 | 1234 | 5
因此,基于上面的表,select不应该返回成员,因为它们也有4级和5级。
如何在MySQL查询中编写它?
答案 0 :(得分:5)
试试这个:
SELECT member
FROM mytable
GROUP BY member
HAVING SUM(level = 2) > 0 AND SUM(level IN (4, 5)) = 0