标签: postgresql distinct-on
我想让Postgres中每个用户拥有最多浏览量的项目。这是我到目前为止的代码:
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