MySQL 删除行(如果过滤了行)

MySQL Removing Rows if One is Filtered

我有table这样的:

id column1  column2
1    a        100
2    a        NULL
3    b        200
4    c        300
5    c        400

我如何 select 行而不包括那些至少有一个 NULL.

的分组行

预期结果:

id column1  column2
3    b        200
4    c        300
5    c        400

不应包含 ID 1 和 2,因为它们包含 column1 = a 值的 NULL 值。

如果一行有重复条目,即 column1 = a,并且这些行至少包含一个 NULL,则不要将其包含在结果集中。

你应该像这样创建一个子查询。

SELECT column1 FROM table WHERE column2 IS null GROUP BY column1

你应该 select 只有那些在他们的 column1 中不包含子 select 值的行。

SELECT * FROM table WHERE column1 NOT IN (SELECT column1 FROM table WHERE column2 IS null GROUP BY column1)

这些sql会对你有所帮助。

select * from test where column1 not in (

SELECT column1 FROM test WHERE column2 IS  null GROUP BY column1)

这里sqlfiddle

谢谢。