How to get number of false in every column of a table?

后端 未结 3 912
离开以前
离开以前 2021-01-21 00:52

I have a table say T_myTable it has 5 columns and all have some values either true or false.

--------------------------------
col1 | col2 | col3 | col4 | col5
--         


        
3条回答
  •  猫巷女王i
    2021-01-21 01:39

    Try this:

    SELECT SUM(CASE col1 WHEN 'false' THEN 1 ELSE 0 END),
        SUM(CASE col2 WHEN 'false' THEN 1 ELSE 0 END),
        SUM(CASE col3 WHEN 'false' THEN 1 ELSE 0 END),
        SUM(CASE col4 WHEN 'false' THEN 1 ELSE 0 END),
        SUM(CASE col5 WHEN 'false' THEN 1 ELSE 0 END)
    FROM T_myTable
    

提交回复
热议问题