我有这样的表:
id column1 column2
1 a 100
2 a NULL
3 b 200
4 c 300
5 c 400
如何选择行而不包括至少有一个NULL
的分组行。
预期结果:
id column1 column2
3 b 200
4 c 300
5 c 400
不应包含ID 1和2,因为它们包含NULL
值的column1 = a
。
如果一行有重复的条目,即。column1 = a
,并且这些行至少包含一个NULL,则不要将其包含在结果集中。
答案 0 :(得分:0)
这些sql对你有帮助。
select * from test where column1 not in (
SELECT column1 FROM test WHERE column2 IS null GROUP BY column1)
谢谢。
答案 1 :(得分:-1)
你应该像这样做一个子查询。
SELECT column1 FROM table WHERE column2 IS null GROUP BY column1
你应该只选择那些不包含their column1中的子选择值的行。
SELECT * FROM table WHERE column1 NOT IN (SELECT column1 FROM table WHERE column2 IS null GROUP BY column1)