数据表结构
username type num
aaaa   玉米 1212
aaaa   玉米  212
bbb     小麦  2323
bbb ....

只有两种产品 玉米和小麦,玉米价格1.5,小麦价格1.2 求总价值?

 

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

 

相关文章:

  • 2021-08-24
  • 2021-10-10
  • 2021-10-23
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-11-21
  • 2021-09-09
  • 2021-09-15
  • 2021-12-12
相关资源
相似解决方案