Last active
July 8, 2017 11:04
-
-
Save ketanbhatt/5522896c4e0fe2d9a5a9554743caf4be to your computer and use it in GitHub Desktop.
Original Query with RawSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
q = MyModel.objects.values('some_fk_id').annotate( | |
avg_duration=Avg('duration'), | |
perc_90_duration=RawSQL('percentile_disc(%s) WITHIN GROUP (ORDER BY duration)', (0.9,)), | |
) | |
print q.query | |
# SELECT "some_fk_id", | |
# AVG("duration") AS "avg_duration", | |
# (percentile_disc(0.9) WITHIN | |
# GROUP ( | |
# ORDER BY duration)) AS "perc_90_duration" | |
# FROM "mymodel" | |
# GROUP BY "some_fk_id", (percentile_disc(0.9) WITHIN | |
# GROUP ( | |
# ORDER BY duration)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment