2014-06-24 99 views
0

我是Postgres的新手。我有一個如下所示的表格:Postgres中的GROUP BY day

User 
---- 
id (int) 
createdOn (bigint) 
isDeleted (boolean) 

createdOn表示自EPOCH以來的毫秒數。我試圖找出有多少用戶是在每一天,有我試過以下的0的標誌請將isDeleted創建的,但它不工作:

SELECT date_trunc('day', u.createdOn) AS "Day" , count(*) AS "No. of users" 
FROM User u 
WHERE u.isDeleted = 0 
GROUP BY 1 
ORDER BY 1; 

如何創建此查詢?

謝謝!

回答

0

你不說什麼不工作,但我想這是date_trunc功能

select 
    date_trunc('day', to_timestamp(createdOn)) as "Day", 
    count(*) as "No. of users" 
from User 
where isDeleted = 0 
group by 1 
order by 1; 
+0

它不顯示每天計數。它只顯示一天。 – user70192

+0

@ user70192發佈一些數據和表格架構:'\ d the_table'。 –

+0

@ user70192新修復(猜測)。如果是秒而不是毫秒,則不需要除以1,000 –