Tutorial : Try to get 3 answsers


Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

p.Id            AS [Post Link],
min(p.Title)         AS "Title",
min(p.ViewCount)     AS "ViewCount",
min(p.Body)          AS "Question",

max(a.Body)          AS "Accepted Answer",
max(a.Score)         AS "Score 1",
max(b.Body)          AS "Answer 2",
max(b.Score)         AS "Score 2",
max(c.Body)         AS "Answer 2",
max(c.Score)         AS "Score 3"

FROM Posts p
left outer JOIN Posts a ON p.AcceptedAnswerId = a.Id -- OR p.ID = a.ParentId
left outer JOIN Posts b ON p.Id = b.ParentId

    -- AND (a.Id is not null) * a.Score / 2 < b.Score 
    --AND b.Id != a.Id
    --where a is null 
    --  a.Id = null
    -- OR(b.Id != a.Id  AND b.Score > a.Score / 2)

left outer JOIN Posts c ON p.Id = c.ParentId 
  and c.Id != b.Id and b.Score > c.Score 

    --  a = null
    --  OR(c.Id != a.Id AND c.Id != b.Id AND c.Score > a.Score / 2)

inner join posttags pt on pt.postid = p.id
inner join tags t on pt.tagid = t.id

t.tagname in ('perl')  -- tag
AND p.PostTypeId = 1   -- select questions
AND (a.Id is null or b.Id is null or a.Id != b.Id)
AND (b.Id is null or c.Id is null or b.Id != c.Id)
AND (a.Id is null or c.Id is null or a.Id != c.Id)

GROUP BY p.Id, p.ViewCount


Enter Parameters

Switch sites:
loading Hold tight while we fetch your results