如果我有一张有三列的桌子
用户标识,事件标识,入口时间
价值观
userid,eventid,entrytime 1 1 NULL 2 1 2012-01-01 1 2 2012-01-01 2 2 2012-01-01 3 1 NULL 3 2 NULL
选择entrytime始终为空的用户id的最佳方法是什么

最佳答案

由于COUNT(entrytime)聚合将消除空值,因此可以使用它通过将useridentrytime子句中的0进行比较来确定哪个HAVING没有非空值。

SELECT userid, COUNT(entrytime)
FROM yourtable
GROUP BY userid
HAVING COUNT(entrytime) = 0

Here is a live demonstration(结果为userid=3)

关于mysql - MySQL避免子查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12954709/

10-11 22:23
查看更多