I want to get the project with the highest number of views for each user in Postgres. This is the code I have so far:
SELECT DISTINCT ON (user_id)
project, user_id, COUNT(view_id) views
FROM
table_name
GROUP BY
user_id
ORDER BY
user_id, views DESC, project