111,129
社区成员
发帖
与我相关
我的任务
分享with a as(
select type,sum(num) as num from foods group by type),
b as(
select type,(case when type='小麦' then 1.2 when type='玉米' then 1.5 end)*num as price from a)
select sum(price) as result from b
select sum(case username when 'aaaa' then num else 0 end)*1.5 + sum(case username when 'bbb' then num else 0 end)*1.2 from tableselect 'a' as name ,100 as number into #temp
union select 'a',200
union select 'b',300
union select 'b',100
select * from #temp
select sum(case name when 'a' then 2 else 5 end * number) as amount from #temp