oracle Group by 分組查詢后,分頁


------------恢復內容開始------------

1.分頁查詢 select count(*) times,title from menulog group by title order by count(*) desc 

2, 生成一個帶rn字段的表tableRN=(SELECT rownum as rn, a.* FROM (select count(*) times,title from menulog group by title order by count(*) desc ) a)

3  select  * from  tableRN where rn between 0 and 6

select * from(SELECT rownum as rn, a.* FROM (select count(*) times,title from menulog group by title order by count(*) desc ) a) 

where rn between 0 and 6

 

 -----------------------

select count(*) times,max(url), title from menulog b group by title order by count(*) desc  

------------------------

今天看公司的代碼,看到很多max或者sum某個字段的值這樣無意義的寫法,一開始很疑惑這樣寫是為了什么。

后來了解到,原來和后面使用到的group by有關,只要select的,不調用聚合函數的,一定要出現在group by里,而group by里出現的,不一定在出現在select里。

------------恢復內容結束------------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM