SQL利用CASE按分组显示合计

按行显示的合计

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;
上一篇:《Genesis-3D开源游戏引擎--横版格斗游戏制作教程08:虚拟键盘实现》--本系列完结


下一篇:weblogic10异常:org.hibernate.hql.ast.HqlToken