首页 > 代码库 > 【MySQl】按所有,今日,本月,24小时每一小时统计

【MySQl】按所有,今日,本月,24小时每一小时统计

-- 24小时
SELECT
HOUR (create_date) AS hours, SUM(source_amount) sm_source_amount, SUM(ticket_count*purchase_price) AS sm_purchase_amount FROM ticket_order WHERE DATE_FORMAT(create_date, %Y-%m-%d) = 2017-05-12 AND scenic_id in(1,2,3); GROUP BY HOUR (create_date); select hour(create_date) as hours,ticket_count,create_date from ticket_order where DATE_FORMAT(create_date,%Y-%m-%d) = 2017-05-12 group by hour(create_date); -- 天 SELECT SUM(source_amount) AS sm_source_amount, SUM(ticket_count) AS sm_ticket_count FROM ticket_order WHERE DATE_FORMAT(create_date, %Y-%m-%d) = 2017-05-17; -- 月 SELECT SUM(source_amount) AS sm_source_amount, SUM(ticket_count) AS sm_ticket_count FROM ticket_order WHERE DATE_FORMAT(create_date, %Y-%m) = 2017-05; -- 所有 SELECT SUM(source_amount) AS sm_source_amount, SUM(ticket_count) AS sm_ticket_count FROM ticket_order;

 

【MySQl】按所有,今日,本月,24小时每一小时统计