如何在 SQL 中选择没有空值的行(在任何列中)?

Con*_*ett 4 mysql sql isnull

我有一张桌子叫table1

它有 100 列:{ col1, col2, ..., col100}

我了解如何在特定列中SELECT包含空值的行,例如:col1

SELECT *
FROM table1
WHERE col1 IS NOT NULL
Run Code Online (Sandbox Code Playgroud)

如何处理任何列中不包含空值的SELECT 所有行

试图

SELECT *
FROM table1
WHERE * IS NOT NULL
Run Code Online (Sandbox Code Playgroud)

但这会返回一个错误MySQL(我正在使用)

Gor*_*off 6

您需要明确列出每一列。我会推荐:

select t.*
from t
where col1 is not null and col2 is not null and . . . 
Run Code Online (Sandbox Code Playgroud)

有些人可能更喜欢更简洁(但速度较慢)的方法,例如:

where concat(col1, col2, col3, . . . ) is not null
Run Code Online (Sandbox Code Playgroud)

尽管您可以使用元数据表或电子表格构建查询,但这实际上并不是表达这一点的简单方法。