We have a RAILS app with Postgres as database and have a use case for drawing a graph over a range of values. Unfortunately the range is a decimal, so I am not able to use the generate_series function of Postgres. Need help in figuring out an optimal way to query this rather than splitting this into 10 different queries. Here's sample data
- We have a table with score | students
- Given a query I would get a set of score-student tuples, from which I get range(min(score), max(score)). For example range(10.25, 16.80)
- We need to break the above range into 10 steps with an interval of 0.655 which is (max-min)10 - 10.25,10.91,11.56,12.22,12.87
- For each step above show the number of students between that score and previous value
- Result would be an array with [(10.25,11232),(10.91,2434),....]
Any way/thoughts to do this in Postgres in a single query or less than 10+ queries?