Query to get count of inserted records hourly wise in postgresql?
-
17-03-2021 - |
Pergunta
I have a table that looks like:
Table name Demo
id creation_date
1 2021-03-06 12:27:48.811
2 2021-03-06 03:56:48.875
3 2021-03-06 03:58:23.567
I need the count of records hourly wise in PostgreSql.
Solução
Postgres can truncate a date to a certain precision:
SELECT DATE_TRUNC('hour', creation_date) FROM demo
So all you have to do is group and count it:
SELECT DATE_TRUNC('hour', creation_date), COUNT(*)
FROM demo
GROUP BY DATE_TRUNC('hour', creation_date)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a dba.stackexchange