计算tableA表中type列有两种类型,计算每个id的每种类型的count和
id type count
1 1 10
2 2 5
1 1 8
4 2 9
方法:
select id
,sum(case when type=1 then count end) as income
,sum(case when type=2 then count end) as expenses
from tableA