sql - select month by day -
i need write query print daily statistics of calls. calls table looks this:
user date 1 3/6/2011 1 15/7/2011 my results should this:
date count 1/6/2011 0 2/6/2011 0 3/6/2011 1 ... 30/6/2011 0 how can that??
try with:
select month.date, count(userid) generate_series(date '2011-06-01', date '2011-06-30', '1 day') month left join calls on (month.date = calls.date) group month.date order month.date asc; more general solution (so can specify month , year parameter):
select month.date, count(userid) generate_series(date '2011-06-01', date '2011-06-01' + interval '1 month' - interval '1 day', '1 day') month left join calls c on (month.date = c.date) group month.date order month.date asc;
Comments
Post a Comment