SELECT TOP 30 pq.Id as question_id, pq.AcceptedAnswerId a...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Interpersonal Skills

Q&A for people looking to improve their interpersonal communication skills

SELECT TOP 30
  pq.Id as question_id,
  pq.AcceptedAnswerId as accepted_answer_id,
  pa.Id as answer_id,
  pa.score,
  pa2.Score as accepted_score,
  p_max.max_score as max_score
FROM posts pq

LEFT JOIN 
  (
    SELECT * 
    FROM posts pa 
    WHERE pa.ParentId IS NOT NULL
  ) pa2 on pa2.Id = pq.AcceptedAnswerId

LEFT JOIN 
  (
    SELECT * 
    FROM posts pa 
    WHERE pa.ParentId IS NOT NULL
  ) pa on pa.ParentId = pq.Id

INNER JOIN
    (
      SELECT p2.ParentId, MAX(p2.Score) AS max_score
      FROM posts p2
      WHERE p2.ParentId IS NOT NULL
      GROUP BY p2.ParentId
    ) p_max on pq.Id = p_max.ParentId AND pq.score = p_max.max_score



WHERE pq.ParentId IS NULL
ORDER BY question_id

Enter Parameters

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