Getting data for histogram plot

前端 未结 10 725
花落未央
花落未央 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:16

    Mike DelGaudio's answer is the way I do it, but with a slight change:

    select floor(mycol/10)*10 as bin_floor, count(*)
    from mytable
    group by 1
    order by 1
    

    The advantage? You can make the bins as large or as small as you want. Bins of size 100? floor(mycol/100)*100. Bins of size 5? floor(mycol/5)*5.

    Bernardo.

提交回复
热议问题