i have following query:
select date_format(created_at,'%y-%m-%d %h:00:00') date, sum(quantity) total request_items group hour( created_at )
it generates report summing quantities hour. got this:
2017-04-01 00:00:00 | 10 2017-04-01 01:00:00 | 05
and requests:
select date_format(created_at,'%y-%m-%d %h:00:00') date, count(id) total requests group hour( created_at )
the principle same, need average amount of items requests `(count of items/count of requests) grouped hour , don't know how it.
if want average, use avg()
:
select date_format(created_at, '%y-%m-%d %h:00:00') date, avg(quantity) avg_quantity items group date(created_at), hour( created_at );
note: should not grouping hour without date -- unless want combine hours different days. seems unlikely because selecting entire date.
Comments
Post a Comment