当前位置:数据库 > Oracle >>

项目中遇到的略复杂的sql(Oracle)

项目中遇到的略复杂的sql(Oracle)
 
每个省回收量排名前5名的回收企业名单
select (select pro.p_name from base_province_list pro where pro.p_index=t.p_index||'0000') p_name
,entp_name,cnt 回收量
  from (select rank() over(partition by p_index order by cnt desc) rk, S.*
          from 
          (select substr(epc.p_index,1,2) p_index,
(select em.entp_name from entp_main em where em.entp_id=epc.hs_entp_id) entp_name,
count(*) cnt
from entp_pd_callback epc
group by substr(epc.p_index,1,2),epc.hs_entp_id) S
          ) T
 where T.rk <=5
 
SELECT REGEXP_SUBSTR(t.entp_craft, '[^,]+', 1, ul) AS entpcraft, t.*
  FROM (select *
          from ENTP_INFO t
         where t.entp_craft like '%,%'
           and t.year is not null
           and is_del = 0) t,
       (SELECT LEVEL ul FROM DUAL CONNECT BY LEVEL <= 100)
 WHERE 1 = 1
   and ul <= LENGTH(t.entp_craft) - LENGTH(REPLACE(t.entp_craft, ',')) + 1
 order by entp_name asc
 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,