idx 类别 金额
----------- -------------------------------------------------- -----------
1 asp 10
1 asp 15
3 php 8
4 sql 22有这样的一个表我怎么样才能合并成下面这样呢
idx 类别 金额
----------- -------------------------------------------------- -----------
1 asp 25
3 php 8
4 sql 22
----------- -------------------------------------------------- -----------
1 asp 10
1 asp 15
3 php 8
4 sql 22有这样的一个表我怎么样才能合并成下面这样呢
idx 类别 金额
----------- -------------------------------------------------- -----------
1 asp 25
3 php 8
4 sql 22
from 表
group by idx, 类别
select idx, 类别, 金额 = sum(金额) from 表 group by idx, 類別
select
idx,
类别,
金额 = (select sum(金额) from 表 where idx=t.idx and 类别=t.类别)
from
表 t
group by
idx, 类别
select
idx,
类别,
sum(金额)金额
from 表
group by
idx,
类别
from 表
group by idx, 类别