sql - Group price by hour -
i have data this
dt | price --------------------------- 2016-02-02 12:33:33 3.3 2016-03-02 12:33:33 3.3 2016-02-02 12:03:33 3.3 2016-02-02 12:50:33 3.3 2016-02-02 13:33:33 3.3
i need summed price grouped hour, though need include year, month , day parts also
desirable result:
2016-02-02 12:00:00 9.9 2016-02-02 13:00:00 3.3 2016-03-02 12:00:00 3.3
i have query, gives result. question is, may there more efficient way this?
my current query:
select to_timestamp(d, 'yyyy-mm-dd hh24:mi:ss') hours, price ( select substr(dt, 1, 13) d, sum(price) price table group substr(dt, 1, 13) ) order hours
try this
select trunc(dt,'hh24'), sum(price) table group trunc(dt,'hh24') order 2 desc;
Comments
Post a Comment