Home > Blockchain >  How can I group by using just one culum?
How can I group by using just one culum?

Time:04-07

Hello everyone im looking for solution tu group by just Store_ID i need to found best employee regarding revenu for each store I know taht in this case i can use LIMIT(2) but i would like to do it in correct way

Data

Expected Result

Expected to have

CodePudding user response:

Use DISTINCT ON:

SELECT DISTINCT ON (store_id) store_id, full_name, revenue
FROM yourTable
ORDER BY store_id, revenue DESC;
  • Related