row_number() over partition in hql

后端 未结 2 514
无人及你
无人及你 2021-02-09 10:40

What is the equivalent of row_number() over partition in hql I have the following query in hql:

select s.Companyname, p.P         


        
2条回答
  •  执念已碎
    2021-02-09 11:22

    Row number by partition looks like this:

    row_number() over (partition by s.Companyname)
    

    You can not use window function row_number in where clause, so you have to do subquery with filter by its value:

    select * from (
      -- here is your query
      select 
        ...,
        row_number() over (partition by s.Companyname) as rowNum
      from ...
      where ...
    ) as res
    where rowNum <= n
    

提交回复
热议问题