Top unanswered MySQL queries

0

Please login or register to vote for this query.

(click on this box to dismiss)

Cognitive Sciences Meta

Q&A about the site for practitioners, researchers, and students in cognitive science, psychology, neuroscience, and psychiatry

-- Find interesting unanswered questions
-- Looks at unanswered questions in your top 6 tags and sorts them by
-- a combined weight which takes into account: score, askers reputation and how
-- well you do on that particular tag

DECLARE @UserId int = ##UserId##

DECLARE @Tag varchar(55) = '##Tag##'

create table #tags (TagId int, [Count] int)

insert #tags 
SELECT TOP 6 
    TagId,
    COUNT(*) AS UpVotes 
FROM Tags
    INNER JOIN PostTags ON PostTags.TagId = Tags.id
    INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
    INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2
WHERE 
    Posts.OwnerUserId = @UserId
GROUP BY TagId
ORDER BY UpVotes DESC


create table #unanswered (Id int primary key)

insert #unanswered 
select q.Id  from Posts q
where (select count(*) from Posts a where a.ParentId = q.Id and a.Score > 0) = 0
and CommunityOwnedDate is null and ClosedDate is null and q.ParentId is null 
and AcceptedAnswerId is null


create table #top (Id int primary key, Weight float)

insert #top
    select top 150
        p.Id, 
        (sum(t.[Count]) / 10.0 + us.Reputation / 200.0 + p.Score * 100) as Weight
    from #unanswered u
    join Posts p on u.Id = p.Id
    join PostTags pt on pt.PostId = u.Id
    join #tags t on t.TagId = pt.TagId  
    join Users us on us.Id = p.OwnerUserId  
    where p.Tags like '%<mysql>%'
    group by p.Id, us.Reputation, p.Score 
   
   select left(cast(p.CreationDate as date), 13) as [Asked],
          cast(tu.Weight as int) [Weight],
          p.Tags,
          tu.Id as [Post Link]
    from #top as tu
    join Posts p on p.Id = tu.Id
    order by p.CreationDate desc, tu.Weight desc

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results