关于sql如何把unchecked、check转换成0、1
我有一个视图中一列是check和unchecked,如何把他们转换成0,1
[解决办法]
在查询的时候写成:case when 列名='check' then 0 else 1 end
[解决办法]
select case when 视图一列 = 'check' then 0 else 1 end from 视图
[解决办法]
CREATE TABLE #tb (a int ,b int ,c int ) INSERT INTO #TB select '1', '2', '0' union all select '0', '0', '1' union all select '0', '1', '0' union all select '1', '1', '1' union all select '0', '0', '0' union all select '2', '2', '1' select sum(case when a=0 then 1 else 0 end) AS a, sum(case when b=0 then 1 else 0 end) as b, sum(case when c=0 then 1 else 0 end) as c from #tb /* a b c ----------- ----------- ----------- 3 2 3 (1 行受影响) */