如何筛选输出,以筛选至少具有一个空值的特定列?
所以对于前。状态列中至少有一个 NULL 值的用户?
ID | Status
B 2017-10-03 08:00:00
B NULL
G 2017-10-03 08:00:00
G 2017-10-03 08:00:00
G 2017-10-03 08:00:00
B 2017-10-03 08:00:00
D 2017-10-03 08:00:00
D NULL
D NULL
最佳答案
您可以使用聚合:
select id
from t
group by id
having count(*) <> count(status);
如果您想要原始行,可以使用exists
:
select t.*
from t
where exists (select 1
from t t2
where t2.id = t.id and t2.status is null
);
关于mysql - SQL - 选择至少包含一个 NULL 值的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59293461/