当前位置: 代码迷 >> Oracle管理 >> 求一sql语句,oracle数据库的解决办法
  详细解决方案

求一sql语句,oracle数据库的解决办法

热度:83   发布时间:2016-04-24 05:45:02.0
求一sql语句,oracle数据库的
A01,A02,A03表中的字段是一样的,是个话单表 
只是按月份建立的,话单的帐期 
表中的字段有电话号码phonenum,一次通话的话费charge 

请问大家,比如说,怎么查1,2,3三个月花费最高的前10名电话号码啊,就是前三个月总和最高的前10个号码? 

谢谢了 
对了,是oracle 数据库

------解决方案--------------------
不知道是不是这个意思

select phonenum,sum(charge) as total from (
select phonenum,charge from a01
union
select phonenum,charge from a02
union
select phonenum,charge from a03
 ) a where rownum<=10 group by phonenum order by total desc;
------解决方案--------------------
try it ..

SQL code
select tt.phonenum  from (         select AA.phonenum,               sum(AA.charge) as all_charges          from (                       select phonenum,charge from A01                union all                select phonenum,charge from A02                union all                select phonenum,charge from A03               )AA         group by AA.phonenum         order by 2 desc       )tt where rownum <= 10;
  相关解决方案