统计记录




--统计1:领用和使用消费券情况
select c.* from(
select '已领取' as '消费券', count(a.id) as '数量' from t1 a
union all
select '已领取并使用' as '消费券', count(b.id) as '数量' from t1 b where b.status=1
)c

--时段统计
select '2016-07-02 00:00:00' as '开始时间','2016-07-03 23:59:59' as '结束时间',t.* from(
select '甲' as '绑定对象', count(a.id) as '数量' from t1 a where LOWER(a.account_type)='jd' and a.enable_flag=1 and a.created_date between '2016-07-02 00:00:00' and '2016-07-03 23:59:59'
union
select '乙' as '绑定对象', count(b.id) as '数量' from t1 b where LOWER(b.account_type)='alipay' and b.enable_flag=1 and b.created_date between '2016-07-02 00:00:00' and '2016-07-03 23:59:59'
union
select '丙' as '绑定对象', count(c.id) as '数量' from t1 c where LOWER(c.account_type)='taobao' and c.enable_flag=1 and c.created_date between '2016-07-02 00:00:00' and '2016-07-03 23:59:59'
) t

--统计2:绑定电商情况
select t.* from(
select '甲' as '绑定对象', count(a.id) as '数量' from t1 a where LOWER(a.account_type)='jd' and a.enable_flag=1
union
select '乙' as '绑定对象', count(b.id) as '数量' from t1 b where LOWER(b.account_type)='alipay' and b.enable_flag=1
union
select '丙' as '绑定对象', count(c.id) as '数量' from t1 c where LOWER(c.account_type)='taobao' and c.enable_flag=1
) t
--统计2:根据用户类型统计电商绑定情况

select t.* from(
select 'Android用户' as '用户类型','甲' as '绑定对象', count(a.id) as '数量' from t1 a
inner join t2 b
on a.customer_id=b.id
inner join t3 c
on b.app_id=c.id
where LOWER(a.account_type)='jd' and a.enable_flag=1 and length(IFNULL(c.device_id,0))>=0 and length(IFNULL(c.device_id,0))<20
union all
select 'Android用户' as '用户类型','乙' as '绑定对象', count(a.id) as '数量' from t1 a
inner join t2 b
on a.customer_id=b.id
inner join t3 c
on b.app_id=c.id
where LOWER(a.account_type)='alipay' and a.enable_flag=1 and length(IFNULL(c.device_id,0))>=0 and length(IFNULL(c.device_id,0))<20

union all
select 'Android用户' as '用户类型','丙' as '绑定对象', count(a.id) as '数量' from t1 a
inner join t2 b
on a.customer_id=b.id
inner join t3 c
on b.app_id=c.id
where LOWER(a.account_type)='taobao' and a.enable_flag=1 and length(IFNULL(c.device_id,0))>=0 and length(IFNULL(c.device_id,0))<20

union all
select 'IOS用户' as '用户类型','甲' as '绑定对象', count(a.id) as '数量' from t1 a
inner join t2 b
on a.customer_id=b.id
inner join t3 c
on b.app_id=c.id
where LOWER(a.account_type)='jd' and a.enable_flag=1 and length(IFNULL(c.device_id,0))>=20

union all
select 'IOS用户' as '用户类型','乙' as '绑定对象', count(a.id) as '数量' from t1 a
inner join t2 b
on a.customer_id=b.id
inner join t3 c
on b.app_id=c.id
where LOWER(a.account_type)='alipay' and a.enable_flag=1 and length(IFNULL(c.device_id,0))>=20

union all
select 'IOS用户' as '用户类型','丙' as '绑定对象', count(a.id) as '数量' from t1 a
inner join t2 b
on a.customer_id=b.id
inner join t3 c
on b.app_id=c.id
where LOWER(a.account_type)='taobao' and a.enable_flag=1 and length(IFNULL(c.device_id,0))>=20

) t


--区分android和ios用户
//ios
select count(id) from t3
where length(IFNULL(device_id,0))>=20 --132367
//android
select count(id) from t3
where length(IFNULL(device_id,0))>=1 and length(IFNULL(device_id,0))<20 --167454


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值