码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2017-07-18 15:25:29      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:mat   from   color   for   code   sum   style   font   pre   

-- 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小时每一小时统计

标签:mat   from   color   for   code   sum   style   font   pre   

原文地址:http://www.cnblogs.com/flydkPocketMagic/p/7200206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!