SQL Query检查表中的40列是否为空

8 sql

如何在表中选择仅包含所有行的NULL值的几列?假设如果Table有100列,则在这100列中,60列具有空值.我如何写出条件来检查60列是否为空.

Jho*_*re- 23

也许用COALESCE

SELECT * FROM table WHERE coalesce(col1, col2, col3, ..., colN) IS NULL
Run Code Online (Sandbox Code Playgroud)


Eri*_*ler 8

where c1 is null and c2 is null ... and c60 is null
Run Code Online (Sandbox Code Playgroud)

使用快捷方式string concatenation(Oracle语法):

where c1||c2||c3 ... c59||c60 is null
Run Code Online (Sandbox Code Playgroud)