标签: mysql
我的表格中包含帐户类型和金额 帐户只有两种(储蓄和信贷):
我创建了一个视图,该视图将根据帐户类型对所有金额总和进行分组。
表格可能如下所示
答案 0 :(得分:0)
使用条件聚合
create view your_view_name as select id, sum(case when account = 'savings' then ammount else 0 end) as saving, sum(case when account = 'credit' then ammount else 0 end) as credit from your_table group by id