我想,以使該選擇必須使用PostgreSQL數據庫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
- 1. ,讓PostgreSQL數據庫
- 2. 在PostgreSQL數據庫
- 3. 的PostgreSQL數據庫
- 4. Drop Postgresql數據庫
- 5. Web2py postgreSQL數據庫
- 6. PostgreSQL的特定數據庫
- 7. 克隆PostgreSQL數據庫
- 8. 啓動PostgreSQL數據庫
- 9. Django數據庫到postgresql
- 10. 的BatchUpdateException在PostgreSQL數據庫
- 11. 清除Postgresql數據庫
- 12. XML數據庫或PostgreSQL
- 13. Postgresql - caculate數據庫大小
- 14. Codeship恢復PostgreSQL數據庫?
- 15. 爲一個PostgreSQL數據庫
- 16. Heroku的PostgreSQL數據庫名
- 17. 的PostgreSQL正從數據庫
- 18. Hekoru上的Postgresql數據庫
- 19. OpenShift PostgreSQL數據庫還原
- 20. PostgreSQL的示例數據庫
- 21. Postgresql數據庫減速
- 22. postgresql/SQL數據庫到kdb
- 23. 連接到postgresql數據庫
- 24. 如何從PostgreSQL數據庫
- 25. SQL查詢Postgresql數據庫
- 26. Postgresql數據庫文檔
- 27. 從PostgreSQL數據庫打印
- 28. 配置Postgresql POSTGIS數據庫
- 29. INSERT跨數據庫PostgreSQL中
- 30. PostgreSQL - 重命名數據庫
對不起,您提供的信息太少,無法回答問題。從數據庫架構的詳細信息開始...... – pavium 2009-09-15 12:22:59
並不要說「想要」 – skaffman 2009-09-15 12:30:34