Created
August 16, 2016 20:54
-
-
Save lloiacono/1e4a3c758ed5c3a7fd2879717501dde4 to your computer and use it in GitHub Desktop.
MySQL queries to calculate AVG and Amount of orders at current hour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#AVG orders at current hour | |
select AVG(orders_count) as avg_orders_per_hour FROM ( | |
select count(entity_id) as orders_count | |
from sales_flat_order sfo | |
where | |
HOUR(created_at) >= HOUR(now()) | |
AND | |
HOUR(created_at) <= HOUR(now()) | |
group by DATE(created_at) order by NULL | |
) avg; | |
#Number of orders at current hour | |
select count(entity_id) | |
from sales_flat_order | |
where created_at >= DATE_FORMAT(NOW(), '%Y-%m-%d %H:00'); | |
#TZ convertion if needed | |
select DATE_FORMAT(CONVERT_TZ(now(), @@session.time_zone, 'Europe/Berlin'), '%Y-%m-%d %H:00'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment