Created
July 5, 2012 22:20
-
-
Save ArthurClune/3056834 to your computer and use it in GitHub Desktop.
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
cursor.execute( | |
"""WITH tr AS (SELECT submitted_time AS tr_from, submitted_time - interval '%(hour)s hour' AS tr_until FROM attacks WHERE id = (SELECT max(id) FROM attacks)) | |
SELECT ident_id, count(*) AS count, max(submitted_time) AS last, min(submitted_time) AS first, (SELECT tr_from FROM tr) AS tr_from, (SELECT tr_until FROM tr) AS tr_until, now() | |
FROM attacks, tr WHERE submitted_time > tr_until AND submitted_time <= tr_from AND ident_id IN (%(idents)s) GROUP BY ident_id ORDER BY count DESC""" , | |
{"hours" : hours, "idents" : ','.join(map(str, ident_ids) )} ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment