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
我想'创建日期的相同小时'在同一小时内意味着相同的绝对时间。所以date_trunc('小时',users.created_at)将是选择的功能。 – 2009-09-15 12:38:04
@incredible_Honk,绝对。使用date_trunc而不是datepart。 – hgmnz 2009-09-15 12:59:22
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;
应该很好地工作。
感谢您的帮助,它工作正常,我想添加一个约束是创建日期=今天 谢谢 – Neveen 2009-09-15 13:00:30
对不起,您提供的信息太少,无法回答问题。从数据库架构的详细信息开始...... – pavium 2009-09-15 12:22:59
并不要说“想要” – skaffman 2009-09-15 12:30:34