Last active
September 8, 2019 01:41
-
-
Save kikoso/f7900d00b34ed15a987e1e5ade475b31 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
;WITH USER_BY_TAG | |
AS | |
( | |
SELECT | |
ROW_NUMBER() OVER(ORDER BY COUNT(*) DESC) Rank, | |
u.Location, | |
COUNT(*) AS UpVotes | |
FROM Tags t | |
INNER JOIN PostTags pt ON pt.TagId = t.id | |
INNER JOIN Posts p ON p.ParentId = pt.PostId | |
INNER JOIN Votes v ON v.PostId = p.Id and VoteTypeId = 2 | |
INNER JOIN Users u ON u.Id = p.OwnerUserId | |
WHERE | |
(LOWER(Location) LIKE '% germany%' OR | |
LOWER(Location) LIKE '% spain%' OR | |
LOWER(Location) LIKE '% holland%' OR | |
LOWER(Location) LIKE '% france%' OR | |
LOWER(Location) LIKE '% italy% ') OR | |
LOWER(Location) LIKE '% netherland%' OR | |
LOWER(Location) LIKE '% united kingdom%' OR | |
LOWER(Location) LIKE '% poland%' OR | |
LOWER(Location) LIKE '% sweden%' | |
AND TagName = 'android' | |
GROUP BY u.Location | |
) | |
SELECT * FROM USER_BY_TAG WHERE rank <= 1000 ORDER BY upvotes DESC ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment