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