Created
June 13, 2013 06:34
-
-
Save dpetrov/5771628 to your computer and use it in GitHub Desktop.
This file contains 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
SELECT | |
total.count, | |
detail.basetag, | |
detail.alarms_id | |
FROM | |
( | |
SELECT | |
basetag, | |
count(*) | |
FROM | |
alarms | |
GROUP BY basetag | |
ORDER BY | |
count DESC, | |
basetag ASC | |
) as total | |
JOIN | |
( | |
SELECT *, | |
row_number() OVER (PARTITION BY basetag ORDER BY firstoccurence ASC, alarms_id ASC) | |
FROM | |
alarms | |
) AS detail ON detail.basetag = total.basetag | |
WHERE row_number = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment