标签:select login ifnull customer log 数据 mys cas group by
业务场景:统计消费总金额大于1000元的,800到1000元的,500到800元的,以及500元以下的人数。
SELECT COUNT(CASE WHEN IFNULL(total_money,0) >=1000 THEN a.customer_id END) AS ‘>1000‘ ,COUNT(CASE WHEN IFNULL(total_money,0) >=800 AND IFNULL(total_money,0) <1000 THEN a.customer_id END) AS ‘800~1000‘ ,COUNT(CASE WHEN IFNULL(total_money,0) >=500 AND IFNULL(total_money,0) <800 THEN a.customer_id END) AS ‘500~800‘ ,COUNT(CASE WHEN IFNULL(total_money,0) <500 THEN a.customer_id END) AS ‘<500‘ FROM mc_userdb.`customer_login` a LEFT JOIN ( SELECT customer_id,SUM(order_money) AS total_money FROM mc_orderdb.`order_master` GROUP BY customer_id) b ON a.`customer_id`=b.`customer_id`
标签:select login ifnull customer log 数据 mys cas group by
原文地址:https://www.cnblogs.com/yizhiamumu/p/9055133.html