Friday, September 2, 2022

How to select the top-N rows per group with SQL in Oracle Database

 with rws as (

  select o.*, row_number () over (

           partition by t_gruppe

           order by t_gruppe

         ) rn

  from   qztuser o

)

  select q_user, t_gruppe, lzudat from rws

  where  lzudat is null and rn <= 3

  order  by t_gruppe;


REF: https://blogs.oracle.com/sql/post/how-to-select-the-top-n-rows-per-group-with-sql-in-oracle-database

No comments: