Oracle 分组统计,抽取每组前十
/**
2018年6月14日 潮州
ORACEL 統(tǒng)計2017年用電量,按行業(yè)分類抽取用電量前十
*/
select *
from (select t.yhbh 用戶編號,
t.yhmc 用戶名稱,
t.jldbh 計量點編號,
(select m.dmbmmc
from npmis_xt_dmbm m
where m.dmfl = 'YDLXDM'
and m.dmbm = t.ydlbdm) 用電類型,
(select m.dmbmmc
from npmis_xt_dmbm m
where m.dmbmbs = (select m.sjdmbmbs
from npmis_xt_dmbm m
where m.dmfl = 'HYFLDM'
and m.dmbm = t.hyfldm)) 上級行業(yè)分類,
(select m.dmbmmc
from npmis_xt_dmbm m
where m.dmfl = 'HYFLDM'
and m.dmbm = t.hyfldm) 行業(yè)分類,
sum(t.jfdl) 總計費(fèi)電量,
row_number() over(partition by t.hyfldm order by sum(t.jfdl) desc) 本行業(yè)排名
from npmis_hs_jldxx t
where t.dfny like '2017%'
and t.ydlbdm in ('100', '200', '260', '300') /**用電類別為:大工業(yè)、非普通工業(yè)、非工業(yè)、商業(yè)*/
and t.jfdl <> 0 /**計費(fèi)電量不為0*/
and t.yhztdm <> '2' /**用戶狀態(tài)不為銷戶*/
group by t.yhbh, t.yhmc, t.jldbh, t.ydlbdm, t.hyfldm
having sum(t.jfdl) > 500000
order by 總計費(fèi)電量)
where 本行業(yè)排名 < 11;
轉(zhuǎn)載于:https://www.cnblogs.com/fooxer/p/9184242.html
總結(jié)
以上是生活随笔為你收集整理的Oracle 分组统计,抽取每组前十的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jQuery基础:下(事件及动画效果)
- 下一篇: 2-数组中重复的数字