Hacker News new | ask | show | jobs
by barrkel 1098 days ago
SQLite would describe this as a feature, because it's a PITA do that type of query otherwise - window functions with rank() or row_number(), or a self-join. (Obviously this specific query could be done with ORDER BY salary DESC LIMIT 1 but if you want the highest paid employee per team or department etc...)
1 comments

> but if you want the highest paid employee per team or department

That's straightforward, no?

   max(salary) over(partition by emp, dept order by salary desc) as top_emp
   ... 
   where top_emp = 1
(You need to put the window in a subquery)