我想执行查询,其中如果前一列中的值为0,则列为false;如果大于0则为true:
例如:
id count
1 1
2 3
3 0
4 5
5 2
结果:
id count
1 true
2 true
3 false
4 true
5 true
答案 0 :(得分:9)
select
id,
case
when count > 0 then 'true'
else 'false'
end as count
from myTable
答案 1 :(得分:6)
select id
, case when count > 0 then cast(1 as bit) else cast(0 as bit) end as count
from myTable