Created
August 23, 2018 10:20
-
-
Save hipertracker/cfbf9a34c683c0341a7f2c3b8ecf7574 to your computer and use it in GitHub Desktop.
Example raw sql in Django
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
| from django.db import connection | |
| def categories(): | |
| sql = ''' | |
| SELECT | |
| SUM(pageview) AS pageview__sum, | |
| substring(url from '^/[^/]+/') AS category | |
| FROM portal_tracker | |
| GROUP BY substring(url from '^/[^/]+/') | |
| HAVING substring(url from '^/[^/]+/') IS NOT NULL | |
| ORDER BY pageview__sum DESC | |
| ''' | |
| with connection.cursor() as c: | |
| c.execute(sql) | |
| return c.fetchall() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment