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
标签:count,分箱,某字段,DISTINCT,cidnum1,mysql,SELECT 来源: https://www.cnblogs.com/cupleo/p/14737605.html