如何获取每个user_id的行数
select distinct on (user_id) *
from some_table
在这样的SQL中:
select user_id, count(*)
from some_table
group by user_id
发布于 2019-02-14 05:33:04
如果您希望能够使用SELECT *
来获取“样本行”,取决于您的表有多大,您可以使用相关子查询来获取该特定用户id的行数:
select distinct on (user_id) *
, (select count (1)
from some_table st2
where st2.user_id = some_table.user_id) as user_row_count
from some_table
https://stackoverflow.com/questions/54677765
复制相似问题