统计各分数段的数据数量
select id, score, date_month,
case when score < 5 then '0-5'
when score>= 5 and score < 10 then '5-10'
when score>= 10 and score < 20 then '10-20'
when score>= 20 and score < 30 then '20-30'
when score>= 30 and score < 50 then '30-50'
when score>= 50 then '50以上'
end as interzone
from table1 B
WHERE is_deleted = 0 AND date_month = 'XXX'
统计各分数段的数据数量(某分数段无数据也存在)
select t3. id, t3. date_month, t3. interzone, t4. XX_id from
( ( select DISTINCT id, date_month, interzone from (
( select interzone from XX_interzone) t1
inner join
( select id, date_month from tablea where is_deleted = 0 ) t2) ) as t3
left join (
select id, XX_id, date_month,
case when score < 5 then '0-5'
when score>= 5 and score < 10 then '5-10'
when score>= 10 and score < 20 then '10-20'
when score>= 20 and score < 30 then '20-30'
when score>= 30 and score < 50 then '30-50'
when score>= 50 then '50以上'
end as interzone
from tableb
where is_deleted = 0 ) as t4
on t3. interzone= t4. interzone and t3. id= t4. id and t3. date_month= t4. date_month)
WHERE t3. id = 'XXX' AND t3. date_month = 'XXX'