Grouping by date, with 0 when count() yields no lines

后端 未结 2 1145
温柔的废话
温柔的废话 2021-01-14 03:44

I\'m using Postgresql 9 and I\'m fighting with counting and grouping when no lines are counted.

Let\'s assume the following schema :

create table vie         


        
2条回答
  •  忘掉有多难
    2021-01-14 04:29

    This query will give you the output what your are looking for,

    select to_char(date_event, 'YYYY-MM-DD HH24:00') as time, count (to_char(date_event, 'HH24:00')) as count from views where date(date_event) > '2012-01-01' and date(date_event) > '2012-01-07' group by time order by time;
    

提交回复
热议问题