码迷,mamicode.com
首页 > 其他好文 > 详细

计数查询统计

时间:2018-05-04 20:21:39      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:订单   span   code   分类   格式   eal   SQ   innodb   ble   

CREATE TABLE `statistic_order` (
  `oid` bigint(20) NOT NULL,
  `o_source` varchar(25) DEFAULT NULL COMMENT ‘来源编号‘,
  `o_actno` varchar(30) DEFAULT NULL COMMENT ‘活动编号‘,
  `o_actname` varchar(100) DEFAULT NULL COMMENT ‘参与活动名称‘,
  `o_n_channel` int(2) DEFAULT NULL COMMENT ‘商城平台‘,
  `o_clue` varchar(25) DEFAULT NULL COMMENT ‘线索分类‘,
  `o_star_level` varchar(25) DEFAULT NULL COMMENT ‘订单星级‘,
  `o_saledep` varchar(30) DEFAULT NULL COMMENT ‘营销部‘,
  `o_style` varchar(30) DEFAULT NULL COMMENT ‘车型‘,
  `o_status` int(2) DEFAULT NULL COMMENT ‘订单状态‘,
  `syctime_day` varchar(15) DEFAULT NULL COMMENT ‘按天格式化日期‘,
  PRIMARY KEY (`oid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


select S.syctime_day,
   sum(case when S.o_source = ‘CDE‘ then 1 else 0 end) as ‘CDE‘,
   sum(case when S.o_source = ‘SDE‘ then 1 else 0 end) as ‘SDE‘,
   sum(case when S.o_source = ‘PDE‘ then 1 else 0 end) as ‘PDE‘,
   sum(case when S.o_source = ‘CSE‘ then 1 else 0 end) as ‘CSE‘,
   sum(case when S.o_source = ‘SSE‘ then 1 else 0 end) as ‘SSE‘
 from statistic_order S where S.syctime_day > ‘2015-05-01‘ and S.syctime_day < ‘2016-08-01‘ 
 GROUP BY S.syctime_day order by S.syctime_day asc;

计数查询

SELECT r.realname ,r.start_time,r.end_time,
sum(case when r.dintype=1 then 1 else 0 end) as ‘zhong‘,
sum(case when r.dintype=2 then 1 else 0 end) as ‘wan‘
from reports r where r.start_time<‘当前时间‘ and r.end_time<‘2018-08-01‘ GROUP by r.realname,r.start_time,r.end_time ORDER by r.realname;

计数查询统计

标签:订单   span   code   分类   格式   eal   SQ   innodb   ble   

原文地址:https://www.cnblogs.com/yixing/p/8992202.html

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