Getting data for histogram plot

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

    SELECT b.*,count(*) as total FROM bins b 
    left outer join table1 a on a.value between b.min_value and b.max_value 
    group by b.min_value
    

    The table bins contains columns min_value and max_value which define the bins. note that the operator "join... on x BETWEEN y and z" is inclusive.

    table1 is the name of the data table

提交回复
热议问题