How can I use SUM for bit columns?

前端 未结 7 1128
栀梦
栀梦 2021-01-01 10:45

How can use the function SUM() for bit columns in T-SQL?

When I try do it as below:

SELECT SUM(bitColumn) FROM MyTable;

I get the e

7条回答
  •  清酒与你
    2021-01-01 11:01

    You could consider 0 as nulls and simply count the remaining values:

    SELECT count(nullif(bitColumn, 0))
    FROM MyTable;
    

提交回复
热议问题