使用rownum统计count()之后的union all 不太好使
1.语法:
select t.srtypeid,cnt,s.fullname name from
(select srtypeid,count(1) cnt
from kfgl_repeat_process_detail
where partition_month='&month'
and (partition_id_region ='®ion_id' or 10 ='®ion_id')
group by srtypeid
order by count(1) desc) t,sdt_servicerequesttype s
where ROWNUM<11
and t.srtypeid=s.srtypeid
得到的结果:
2.语法二:
select t2.srtypeid,t2.cnt,s.fullname name from
( select srtypeid,count(1) cnt
from report_repeat_cmplt_pro_detail h
where partition_month='&month'
and h.pro_region_id ='®ion_id'
group by h.srtypeid
order by count(1) DESC
) t2,sdt_servicerequesttype s
where rownum<11
and t2.srtypeid=s.srtypeid
union all 之后:
3.语法三:
select t.srtypeid,cnt,s.fullname name from
(select srtypeid,count(1) cnt
from kfgl_repeat_process_detail
where partition_month='&month'
and (partition_id_region ='®ion_id' or 10 ='®ion_id')
group by srtypeid
order by count(1) desc) t,sdt_servicerequesttype s
where rownum<11
and t.srtypeid=s.srtypeid
UNION ALL
select t2.srtypeid,t2.cnt,s.fullname name from
( select srtypeid,count(1) cnt
from report_repeat_cmplt_pro_detail h
where partition_month='&month'
and h.pro_region_id ='®ion_id'
group by h.srtypeid
order by count(1) DESC
) t2,sdt_servicerequesttype s
where rownum<11
and t2.srtypeid=s.srtypeid
查询结果:
语法一和语法三输入的条件是一样的,在此条件下语法三没有查询结果。语法三得到的变的混乱了。
从此貌似可以看出union all 得到的查询结果并不是单个查询结果出来之后累加在一起的?
截止发文前还是有疑问,没有完全搞清楚,希望有读者解答。