日期:2014-05-17 浏览次数:20953 次
select 单据号 ,姓名,sum(金额) from table group by 单据号,姓名
------解决方案--------------------
with tab as (
select 'A' as djh,'name1' as name,100 as je from dual
union all
select 'A' as djh,'name1' as name,200 as je from dual
union all
select 'A' as djh,'name2' as name,300 as je from dual
union all
select 'B' as djh,'name1' as name,400 as je from dual
union all
select 'B' as djh,'name2' as name,500 as je from dual
)
select djh,name,sum(je) as je from tab group by djh,name
------解决方案--------------------
--这个蛮基础的啊 楼主没认真去想吧 select 单据号 , 姓名, sum(金额) 总金额 from tb group by 单据号,姓名
------解决方案--------------------
select 单据号 , 姓名, sum(金额) 总金额 from tb group by 单据号,姓名
------解决方案--------------------
SQL> with t as ( 2 select 'A' 单据号,'name1' 姓名,100 金额 from dual union all 3 select 'A','name1',200 from dual union all 4 select 'A','name2',300 from dual union all 5 select 'B','name1',400 from dual union all 6 select 'B','name2',500 from dual) 7 select 单据号,姓名,sum(金额) 8 from t 9 group by 单据号,姓名; 单据号 姓名 SUM(金额) ------ ----- ---------- A name1 300 A name2 300 B name1 400 B name2 500