Selecting top n elements of a group in Oracle

前端 未结 5 683
执念已碎
执念已碎 2020-12-10 22:14

I have an Oracle table which has a name,value,time columns.Basically the table is for logging purposes to store what are the changes made to a particular name,what was the p

5条回答
  •  天涯浪人
    2020-12-10 22:51

    I offer my quick fix. This query groups and counts in descending order (in the inner query). The Outer query simply allows you to define the number of rows to display (:pRows).

    Select * from
    (Select
         group_field,
         count(*) Cnt
    From
         record_source(s)
    Where
         Conditions
    Order by
         Count(*) Desc) x
    Where
      rownum < :pRows+1;
    

提交回复
热议问题