我要查询一张表的全部字段,然后按ID分组,把金额加起来,每个ID只显示1条,这句SQL怎么写呢,弄了好长时间了
解决方案 »
- 在线问 IBMP550 POWER6 配哪款 oracle10g
- 分拆字段,太难了.
- hp-ux安装oracle10;有两个问题指教
- Oracle递归查询!
- 古老的问题,连接Oracle时出错:System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.
- Oracle Database 10g Express Edition登录问题
- 急求TXT文件导入ORACLE数据库的方法
- >>求oracle 9i的入门教材!!
- 急....,在线等候,从oracle下载9i的问题
- max的問題,初學.
- data guard的备库,有库文件吗?
- 在Oracle里创建包体出错!谢谢有缘人!!!!!
select count(金额) from table group by ID
select ID,max(col1), max(col2)...., count(金额) from table group by ID
建议使用分析函数,计算金额也不能用count
select id,col1,cole2,col3... sum(金额)over(partition by id order by 1) totalAmt from table
select a.sum,c.*
(select id as , count(金额) sum from table group by ID) a
inner join
(select * from
(select *,over(partition by id order by 金额) num from table ) b
where b.num=1) c
on a.id=c.id
where b.id=a.id;
查询所有字段 = select * from table
按ID分组 = group by id
这两条本身就是矛盾的,结果想要怎么展示?
将金额累加起来用sum,然后用group by ,至于你要的粒度到哪个级别的就group by到那个级别