Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- . Print top 10 users - user_id and their rank - in ascending order of their ranks where rank is given by
- the total compost trash disposed by them (total weight of compost trash thrown, regardless of trash
- type, into the compost bin). Partial credit will be given for printing the top 10 user_id without their rank
- */
- SELECT user_id,
- RANK() OVER
- (ORDER BY sum(LoadObservation.weight) DESC
- ) user_id,
- sum(LoadObservation.weight)
- FROM LocationSensor, WasteBin, CompostBin, LocationObservation, LoadObservation
- WHERE WasteBin.waste_bin_id = CompostBin.waste_bin_id
- AND LocationObservation.x = WasteBin.x
- AND LocationObservation.y = WasteBin.y
- AND LoadObservation.timestamp = LocationObservation.timestamp
- AND LocationObservation.sensor_id = LocationSensor.sensor_id
- GROUP BY user_id
- ORDER BY user_id
- LIMIT 0,10;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement