Answer the question
In order to leave comments, you need to log in
Grouping in PostgreSQL?
There is a table:
id| country | salary
1 | sweden | 3000
2 | germany| 3900
3 | sweden | 3500
4 | sweden | 29005
| germany| 3300
Required:
SELECT id, max(salary) FROM t GROUP BY country;
Answer the question
In order to leave comments, you need to log in
SELECT t.id, t.country, t.salary
FROM t
INNER JOIN
( SELECT country, max(salary) AS max_salary FROM t GROUP BY country ) tm
ON t.country = tm.country AND t.salary = tm.max_salary
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question