select 列1 ,列2 , sum(case 列4 when 'false' then -列3 else 列3 end) from yourtable group by 列1,列2 order by 列1,列2
厉害! 我平时很少用到case,又学到东西了,呵呵
select 列1 ,列2 , sum(case when 列4='false' then -列3 else 列3 end) from yourtable group by 列1,列2 order by 列1,列2
如果我要是想去掉相减后得0的数值是不是这样写?select 列1 ,列2 , sum(case when 列4='false' then -列3 else 列3 end) as abc from yourtable where abc <> 0 group by 列1,列2 order by 列1,列2有错误 我该怎么改?
select 列1 ,列2 , sum(insull(列3,0) * (case when 列4='ture' then 1 else -1 end)) ABC from yourtable group by 列1,列2 having sum(列3 * (case when 列4='ture' then 1 else -1 end)) <> 0 order by 列1,列2
select 列1 ,列2 , sum(isnull(列3,0) * (case when 列4='ture' then 1 else -1 end)) ABC from yourtable group by 列1,列2 having sum(列3 * (case when 列4='ture' then 1 else -1 end)) <> 0 order by 列1,列2--insull----> isnull
group by 列1,列2 order by 列1,列2
我平时很少用到case,又学到东西了,呵呵
group by 列1,列2 order by 列1,列2
from yourtable
where abc <> 0
group by 列1,列2
order by 列1,列2有错误
我该怎么改?
sum(insull(列3,0) * (case when 列4='ture' then 1 else -1 end)) ABC
from yourtable
group by 列1,列2
having sum(列3 * (case when 列4='ture' then 1 else -1 end)) <> 0
order by 列1,列2
sum(isnull(列3,0) * (case when 列4='ture' then 1 else -1 end)) ABC
from yourtable
group by 列1,列2
having sum(列3 * (case when 列4='ture' then 1 else -1 end)) <> 0
order by 列1,列2--insull----> isnull