问题 I have a table with id , year and count . I want to get the MAX(count) for each id and keep the year when it happens, so I make this query: SELECT id, year, MAX(count) FROM table GROUP BY id; Unfortunately, it gives me an error: ERROR: column "table.year" must appear in the GROUP BY clause or be used in an aggregate function So I try: SELECT id, year, MAX(count) FROM table GROUP BY id, year; But then, it doesn't do MAX(count) , it just shows the table as it is. I suppose because when grouping