-
-
Save gordonje/eb16a1939da33c07c610 to your computer and use it in GitHub Desktop.
max lottery wins by a person at each store
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
-- what we want our distinct stores and the max number of wins for a person that played there | |
SELECT "AGENT NAME", max(count_person_wins), max(sum_person_winnings) | |
FROM ( | |
-- gets us the number of wins per person for each store | |
SELECT | |
"AGENT NAME" | |
, "FIRSTNAME" | |
, "LASTNAME" | |
, "CITY" | |
, "STATE" | |
, COUNT(*) as count_person_wins | |
, SUM("PRIZE VALUE") as sum_person_winnings | |
FROM data | |
WHERE "AGENT NAME" IS NOT NULL | |
GROUP BY 1, 2, 3, 4, 5 | |
ORDER BY "AGENT NAME", COUNT(*) DESC | |
) as sub_q | |
GROUP BY 1 | |
ORDER BY max(count_person_wins) DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment