sql - PostgreSQL: Aggregate by more than one column -
i have following data format:
id eventtime use 2015-01-01 00:00:00-01 5.2 . . 2015-06-06 23:59:50-01 5.7 b . .
i'm trying output of form:
id eventtime use 2015-01-01 1200 . 2015-06-06 1400 . b 2015-01-01 1500
basically sum of item use every user each day in database.
i tried
select id, eventtime, sum(use) table group id,eventtime
i got aggregate in case can't make sense of i.e doesn't add should. appreciated, in advance!
you need convert eventtime
date removing time component. think simplest way using date_trunc()
:
select id, date_trunc('day', eventtime) eventday, sum(use) table group id, eventday order id, eventday;
i'm not sure why sample query has id
in select
, user
in group by
.
Comments
Post a Comment