mysql 按某字段分组分箱聚合查询


SELECT cidnum1,count(*) as num from 
(
SELECT DISTINCT id,cidnum,
(CASE 
        WHEN 0<cidnum and cidnum<=1 THEN '1个公司'
        WHEN 1<cidnum and cidnum<=5 THEN '2-5个公司'
        WHEN 5<cidnum and cidnum<=10 THEN '6-10个公司'
        when 10<cidnum and cidnum<=50 then '11-50个公司'
        when 50<cidnum and cidnum<=100 then '51-100个公司'
        when 100<cidnum and cidnum<=500 then '101-500个公司'
        when 501<cidnum and cidnum<=1000 then '501-1000个公司'
        ELSE '1001个公司以上'
END) as cidnum1
FROM TABLE
where ***
) a
GROUP BY cidnum1
ORDER BY num desc

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM