I have a table of employees with their name, dept and salary.
See here
I want to fetch 2 highest salary employees from every dept
This is how I achieved in MySql,
select dept, name, salary from (
select dept, name, salary,
row_number() over (
partition by dept
order by salary desc
) rn
from
employees as T
)as T
where T.rn < 2;
How would I write this with
Laravel Eloquent or Query Builder (Without using raw)?
question from:
https://stackoverflow.com/questions/66056691/how-to-use-partition-in-laravel 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…