1.背景要求:统计消费金额大于1000元,800到100元,500到800元,500元以下的人数。
select
count(case when ifnull(total_money,0)>=1000 then a.user_id end) as '大于100',
count(case when ifnull(total_money,0)>=800 and ifnull(total_money,0)<1000 then a.user_id end) as '大于100',
count(case when ifnull(total_money,0)>=500 and total_money<=800 then a.user_id end) as '大于800小于1000',
count(case when ifnull(total_money,0)>=1000 then a.user_id end) as '大于500 小于800‘,
count(case when ifnull(total_money,0)<=500 then a.user_id end) as '小于500‘
from a