Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. ;WITH USER_BY_TAG
  2. AS
  3. (
  4. SELECT
  5. ROW_NUMBER() OVER(ORDER BY COUNT(*) DESC) Rank,
  6. u.Location,
  7. COUNT(*) AS UpVotes
  8. FROM Tags t
  9. INNER JOIN PostTags pt ON pt.TagId = t.id
  10. INNER JOIN Posts p ON p.ParentId = pt.PostId
  11. INNER JOIN Votes v ON v.PostId = p.Id and VoteTypeId = 2
  12. INNER JOIN Users u ON u.Id = p.OwnerUserId
  13. WHERE
  14. (LOWER(Location) LIKE '% germany%' OR
  15. LOWER(Location) LIKE '% spain%' OR
  16. LOWER(Location) LIKE '% holland%' OR
  17. LOWER(Location) LIKE '% france%' OR
  18. LOWER(Location) LIKE '% italy% ') OR
  19. LOWER(Location) LIKE '% netherland%' OR
  20. LOWER(Location) LIKE '% united kingdom%' OR
  21. LOWER(Location) LIKE '% poland%' OR
  22. LOWER(Location) LIKE '% sweden%'
  23. AND TagName = 'android'
  24. GROUP BY u.Location
  25.  
  26. )
  27.  
  28. SELECT * FROM USER_BY_TAG WHERE rank <= 1000 ORDER BY upvotes DESC ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement