按行显示的合计

select 
    game, 
    sum(purchase) as purchase_sum 
from
    purchase 
group by 
    game;

按列显示的合计

select 
    sum(case when game = 'action'
             then purchase else 0 end) as sum_action,
    sum(case when game = 'puzzle'
             then purchase else 0 end) as sum_puzzle,
    sum(case when game = 'RPG'
             then purchase else 0 end) as sum_rpg 
from 
    purchase;

 

相关文章:

  • 2021-06-14
  • 2021-12-07
  • 2021-09-01
  • 2022-03-04
  • 2021-12-19
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-23
  • 2021-10-12
  • 2022-12-23
  • 2021-07-26
  • 2022-01-01
  • 2022-03-04
相关资源
相似解决方案