select sum(if (a>100) 1 else 0 ) from table
我希望计算 if (a>100) 时返回1 否则返回0 而CASE语句只能使用固定的值不能是用 大于小于号
sum(case datepart(hour , in_date) when 0 then 1 else 0 end)
只能
这样
我希望计算 if (a>100) 时返回1 否则返回0 而CASE语句只能使用固定的值不能是用 大于小于号
sum(case datepart(hour , in_date) when 0 then 1 else 0 end)
只能
这样
select sum(case (a/100) when 0 then 0 else 1 end) from table
select sum(case when a> 100 then 1 else 0 end ) from table
set @s='a'
select case when @s='a' then '等于' else '不等于' endselect case @s when 'a' then '等于' else '不等于' end2种用法