select tradeid,sum(totalvalue) from tablename group by tradeid
------解决方案--------------------
SQL code
select tradeid ,sum(totalvalue)
from(
select distincts
tradeid , totalvalue
from a
)
group by tradeid
------解决方案-------------------- select sum(totalvalue) from test order by tradeid,demin_class_id group by tradeid,demin_class_id;
------解决方案-------------------- 不是很明白楼主意思。按报销单求费用和的话就直接 select sum(totalvalue) from tablename group by tradeid; 求总和的话就 select sum(totalvalue) from tablename; 不会问的这么简单吧。如果不是再说明白点。
------解决方案-------------------- 是每个报销单号的所有费用.还是所有有费用? 每个: select tradeid,sum(totalvalue) from 表名 group by tradeid; 所有: select sum(totalvalue) from 表名;
------解决方案-------------------- select demin_class_id,sum(totalvalue) from test order by demin_class_id group by demin_class_id;
------解决方案--------------------
------解决方案-------------------- 是不是这个答案呢 WITH a AS (SELECT '1' ID ,1 cid ,10 sal FROM dual UNION ALL SELECT '1' ID ,2 cid ,10 sal FROM dual UNION ALL SELECT '1' ID ,3 cid ,10 sal FROM dual UNION ALL SELECT '2' ID ,2 cid ,20 sal FROM dual UNION ALL SELECT '2' ID ,3 cid ,20 sal FROM dual UNION ALL SELECT '2' ID ,5 cid ,20 sal FROM dual UNION ALL SELECT '2' ID ,6 cid ,20 sal FROM dual ) SELECT 'id-'||nvl(ID,'总和') ,SUM(sal) FROM a group by rollup(ID) UNION ALL SELECT 'cid-'||nvl(''||cid,'总和') ,SUM(sal) FROM a group by rollup(cid);