##查询到店会员人数
SELECT '0-7天' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS B UNION ALL
SELECT '7-15天' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS C UNION ALL
SELECT '15-30天' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS D UNION ALL
SELECT '30-60天' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS E UNION ALL
SELECT '60天以上' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS D;
##查询到店游客人数
SELECT '0-7天' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM ( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS B UNION ALL
SELECT '7-15天' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM ( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS B UNION ALL
SELECT '15-30天' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM ( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS B UNION ALL
SELECT '30-60天' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM ( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS B UNION ALL
SELECT '60天以上' AS day, COUNT(*) AS count FROM (
SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成') AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM ( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id ) AS B
##会员人数占比
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '0-7天' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*)
FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT
cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是'
GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A UNION ALL
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '7-15天' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*) FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id ) GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A UNION ALL
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '15-30天' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*) FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (
SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A UNION ALL
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '30-60天' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*) FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id
)
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A UNION ALL
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '60天以上' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*)
FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (
SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id
)
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A
##游客人数占比
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '0-7天' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*)
FROM mmc_order AS ord,mmc_member as mb
WHERE
ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (
SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 37 AND cd.state = '是'
GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-08-25'
AND '2017-08-25' AND ord.st_id = 37 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 35 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 37
AND cd.state = '是' GROUP BY mb.mb_id) GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A UNION ALL
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '7-15天' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*) FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 35 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 35
AND cd.state = '是' GROUP BY mb.mb_id) GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A UNION ALL
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '15-30天' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*)
FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 35 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 35
AND cd.state = '是' GROUP BY mb.mb_id) GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A UNION ALL
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '30-60天' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*)
FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (
SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 35 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 35
AND cd.state = '是' GROUP BY mb.mb_id) GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A UNION ALL
SELECT day,CONCAT(count,'%') as bili FROM(
SELECT '60天以上' AS day, ROUND(COUNT(*)/(SELECT COUNT(*) FROM (
SELECT COUNT(*) FROM mmc_order AS ord,mmc_member as mb
WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (
SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id )
GROUP BY ord.mb_id) as A)*100,2) AS count
FROM ( SELECT COUNT(mb_id) FROM mmc_order AS ord WHERE substring(ord.ord_create_time, 1, 10) BETWEEN '2017-09-11'
AND '2017-09-11' AND ord.st_id = 35 AND ord.ord_state in ('待评价','已完成')
AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 35 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡' AND cd.st_id = 35
AND cd.state = '是' GROUP BY mb.mb_id) GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A ) GROUP BY ord.mb_id ) AS B ) as A ;
##会员消费总额
SELECT '0-7天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) UNION ALL
SELECT '7-15天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) UNION ALL
SELECT '15-30天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) UNION ALL
SELECT '30-60天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) UNION ALL
SELECT '60天以上' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A ) ;
##游客消费总额
SELECT '0-7天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A ) UNION ALL
SELECT '7-15天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A ) UNION ALL
SELECT '15-30天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A ) UNION ALL
SELECT '30-60天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A ) UNION ALL
SELECT '60天以上' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A );
#会员消费占比
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '0-7天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A )) as A) as B UNION ALL
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '7-15天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A )) as A) as B UNION ALL
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '15-30天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A )) as A) as B UNION ALL
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '30-60天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A )) as A) as B UNION ALL
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '60天以上' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT A.mb_id FROM
( SELECT mb.mb_id FROM mmc_member_card AS cd, mmc_member AS mb
WHERE mb.mb_id = cd.mb_id AND cd.card_type = '会员充值卡'
AND cd.st_id = 35 AND cd.state = '是' GROUP BY mb.mb_id ) AS A)
GROUP BY ord.mb_id) as A )) as A) as B ;
##游客消费占比
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '0-7天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A )) as A) as B UNION ALL
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '7-15天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A )) as A) as B UNION ALL
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '15-30天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A )) as A) as B UNION ALL
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '30-60天' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A )) as A) as B UNION ALL
SELECT day,CONCAT(ROUND(bl*100,2),'%') as bili FROM (
SELECT day,money/(SELECT ROUND(IFNULL(SUM(ord.ord_pay_money),0),2) as total FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')) as bl FROM (
SELECT '60天以上' as day, ROUND(IFNULL(SUM(ord_pay_money),0),2) as money FROM mmc_order as ord where ord.ord_state in ('已完成','待评价') AND ord.ord_type in ('门店下单','购买套餐')
AND substring(ord.ord_create_time,1,10) BETWEEN '2017-09-11' AND '2017-09-11' AND ord.st_id=35 AND ord.mb_id NOT in (SELECT mb_id FROM (
SELECT ord.mb_id FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN (SELECT mb_id FROM ( SELECT ord.mb_id
FROM mmc_order AS ord,mmc_member as mb WHERE ord.st_id = 37 AND mb.mb_id=ord.mb_id
AND ord.mb_id NOT IN ( SELECT cd.mb_id
FROM mmc_member_card AS cd, mmc_member AS mb WHERE mb.mb_id = cd.mb_id
AND cd.card_type = '会员充值卡' AND cd.st_id = 37 AND cd.state = '是' GROUP BY mb.mb_id)
GROUP BY ord.mb_id) as A) GROUP BY ord.mb_id) as A )) as A) as B ;
SQL稿
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 什么是我的大学 感谢各位,我的年总结,是一个问题的答案,这个问题是:什么是我的大学? 去年高考后,我问了自己一个问...
- 环境:Windows下,已有VC++6.0的编译器。 1.新建c:\esqlc目录。 将SQL SEVER安装盘上...
- 在实验室处理数据时,遇到一张20w记录的表需要恢复,初以为直接在dbms中直接导入sql即可,然而显示内存不够,无...