Get popular tags first

0

Please login or register to vote for this query.

(click on this box to dismiss)

Craft CMS Meta

Q&A about the site for administrators, end users, developers and designers for Craft CMS

-- Top users by tag and Users.location
-- Currently only looking at score for questions.  Not sure how to fix this yet.

--SELECT TOP 20 * FROM Posts


select
  Answers.OwnerUserId AS UserId, 
  Tags.Id As TagId, 
  Tags.TagName, 
  SUM(Answers.Score) AS Score
    FROM Tags
    JOIN PostTags ON Tags.Id = PostTags.TagId
    JOIN Posts ON Posts.Id = PostTags.PostId  
    JOIN Posts Answers ON Answers.ParentId = Posts.Id 
    JOIN Users ON Users.Id = Answers.OwnerUserId 
    WHERE Answers.OwnerUserId is not null and Answers.OwnerUserId <> ''
    and
(
  lower(Users.location) like '%united kingdom%' or
(lower(Users.location) like '%england%' 
and lower(Users.location) not like '%new england%'
) 
or
(lower(Users.location) like '%london%' 
and lower(Users.location) not like 'london%on' 
and lower(Users.location) not like '%ontario%'
and lower(Users.location) not like '%canada%'
)
or
(lower(Users.location) like '%uk%' 
and lower(Users.location) not in ('breukelen','takatsuki','phuket','fukushima','ukarine','ukrain','pewaukee','tutukaka','waukesha','pennsauken','fukuoka','fukui','shinjuku','ukraine','waukegan','iizuka','tukwilla','shinjuku','fukuoka','kentukcy','sukadana','tsukuba','london\,\ ky','luka','yokosuka','ortenaukreis','takarazuka','mukwonago','ukrane','sukabumi','milwaukee'))

or
lower(Users.location) like '%sussex%'
or
lower(Users.location) like '%bristol%')
  GROUP BY Answers.OwnerUserId, Tags.Id, Tags.TagName
-- get most popular first 
order by score desc;

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results