Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get frequency distribution of a decimal range in MySQL

Tags:

sql

mysql

I'm looking for an elegant way (in terms of syntax, not necessarily efficient) to get the frequency distribution of a decimal range.

For example, I have a table with ratings column which can be a negative or positive. I want to get the frequency of rows with a rating of certain range. - ... - [-140.00 to -130.00): 5 - [-130.00 to -120.00): 2 - [-120.00 to -110.00): 1 - ... - [120.00 to 130.00): 17 - and so on.

[i to j) means i inclusive to j exclusive.

Thanks in advance.

like image 696
Mikko Avatar asked Dec 02 '25 08:12

Mikko


1 Answers

You could get pretty close using 'select floor(rating / 10), count(*) from (table) group by 1'

like image 112
ethrbunny Avatar answered Dec 03 '25 23:12

ethrbunny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!