java - How to group results by intervals? -
I have a table with an event with "speed" properties.
Distribution of this property to see the statistical, I want to group the result by interval, we say:
[0-49.99 km / h] 3 items [50-100 km / h] 13 objects [100 -150 km / h] 50 objects etc.
This will allow me to see that most objects are in a fixed interval.
Obviously it can be done with many questions in the appropriate position, such as:
Count from GaEvent where speed => MIN and speed < Max
But this is extremely inefficient.
Cheers!
In order to deal with this in more than one SQL alone, the question is against the one derived table in the table in which the minimum of your histogram For example:
Select t.min, t.max, count (*) (Choose as minimum 0, 14.9 max. Choose Association 15, 29.9 Union Choose 30, 44.9 Union ...) t.min and t.max group between c.speed at t.min by t.min by t.max Except the exterior cars with the order left C is left. Max | Count ----------------- 0 | 14.9 | 1 15 | 29.9 | 1 30. 44.9 | 2
It is very dependent that the database vendor you are using, for example, is a concept of PostGrace SQL that can make this kind of query a lot easier and you can use the "histogram The table "can be stopped by the need to make itself.
Although it comes to hibernate, it seems very little in the way and it will apply anything like this. It can be very well a scenario where you use raw SQL for the query You want to drop down, and / or calculate in Java.
Comments
Post a Comment