如果我有一个包含三列的表
userid,eventid,entrytime
和价值观一样
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
选择入口时间始终为NULL的用户标识的最佳方法是什么
答案 0 :(得分:4)
由于COUNT(entrytime)
聚合将消除NULL值,因此您可以使用它来确定哪个userid
没有entrytime
的非空值,方法是将其与{{1}中的0进行比较}。clause。
HAVING
Here is a live demonstration(结果为SELECT userid, COUNT(entrytime)
FROM yourtable
GROUP BY userid
HAVING COUNT(entrytime) = 0
= 3)
答案 1 :(得分:3)
试试这个:
select userid from
(select userid,entrytime,count(*) from yourtable
group by userid,entrytime)a
group by userid
having count(*)=1 and max(entrytime) is null
答案 2 :(得分:1)
SELECT DISTINCT t1.UserId
FROM <TableName> t1
LEFT JOIN <TableName> t2 ON t1.UserID = t2.UserID AND t2.EntryTime IS NOT NULL
WHERE t2.UserID IS NULL
答案 3 :(得分:-1)
select userid from table_name where entrytime is null