获取列值不为 NULL 的每列计数

2021-12-30 00:00:00 count mysql

我有一张表格,表格中有 5 列.我想要列值不为空的每一列的行数.

I have a table and 5 columns in the table. I want row count for each column where column value is not null.

column1 column2 column3 column4 column5
1        2        2       2        2
2        2        2       NULL     2     
3        NULL     2       2        NULL
NULL     NULL     2       2        NULL
NULL     NULL     2       2        NULL

我应该得到像 3,2,5,4,2 这样的输出

i should get output like 3,2,5,4,2

推荐答案

所提供的解决方案对我不起作用.我不得不修改代码如下:

The solutions offered did not work for me. I had to modify the code as follows:

SELECT 
COUNT(NULLIF(Column1,'')),
COUNT(NULLIF(Column2,'')),
COUNT(NULLIF(Column3,'')),
COUNT(NULLIF(Column4,'')),
COUNT(NULLIF(Column5,''))
FROM Table1

相关文章