如何获取表的每一列中的假数? [英] How to get number of false in every column of a table?

查看:27
本文介绍了如何获取表的每一列中的假数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,上面写着 T_myTable,它有 5 列,并且都有一些值,要么是真要么是假.

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
--------------------------------
true | false|false|true |false
false| true |false|false|false
true | false|false|true |false
false| false|false|true |false

我想得到如下结果:-

col1 | col2 | col3 | col4 | col5
--------------------------------
2    | 3    |4     |1     |4

这里的这些数字是假的.varchar 也是 true 和 false.

Where these numbers here are numbers of false. Also true and false are varchar.

推荐答案

这个:

SELECT SUM(CASE WHEN Col1 = 'false' THEN 1 ELSE 0 END) AS Col1
    , SUM(CASE WHEN Col2 = 'false' THEN 1 ELSE 0 END) AS Col2
    , SUM(CASE WHEN Col3 = 'false' THEN 1 ELSE 0 END) AS Col3
    , SUM(CASE WHEN Col4 = 'false' THEN 1 ELSE 0 END) AS Col4
    , SUM(CASE WHEN Col5 = 'false' THEN 1 ELSE 0 END) AS Col5
FROM T_myTable

这篇关于如何获取表的每一列中的假数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆