Getting data for histogram plot

前端 未结 10 715
花落未央
花落未央 2020-11-29 15:27

Is there a way to specify bin sizes in MySQL? Right now, I am trying the following SQL query:

select total, count(total) from faults GROUP BY total;
<         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 16:21

    select "30-34" as TotalRange,count(total) as Count from table_name
       where total between 30 and 34
    union (
    select "35-39" as TotalRange,count(total) as Count from table_name 
       where total between 35 and 39)
    union (
    select "40-44" as TotalRange,count(total) as Count from table_name
       where total between 40 and 44)
    union (
    select "45-49" as TotalRange,count(total) as Count from table_name
       where total between 45 and 49)
    etc ....
    

    As long as there are not too many intervals, this is a pretty good solution.

提交回复
热议问题