【发布时间】:2009-09-15 12:19:25
【问题描述】:
我想通过使用 postgresql 数据库进行查询,选择具有相同用户名和相同创建日期的用户
【问题讨论】:
-
抱歉,您提供的信息太少,甚至无法开始回答问题。从您的数据库架构的详细信息开始...
标签: sql postgresql
我想通过使用 postgresql 数据库进行查询,选择具有相同用户名和相同创建日期的用户
【问题讨论】:
标签: sql postgresql
这样的事情应该可以解决问题。这将返回任何用户/小时对以及计数(未经测试):
select users.username, datepart('hour', users.created_at), count(*) from users
inner join users u2
on users.username = u2.username
and datepart('hour', users.created_at) = datepart('hour', u2.created_at)
group by users.username, datepart('hour', users.created_at) having count(*) > 1
【讨论】:
select u.*
from users u
join (
select username, date_trunc('hour', creation_timestamp)
from users
group by 1, 2
having count(*) > 1
) as x on u.username = x.username
order by u.username;
应该很好用。
【讨论】: