Users with reciprocal *Accepted* answers

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

WITH QandA_users AS (
    SELECT      q.OwnerUserId   AS userQ
                , a.OwnerUserId AS userA
    FROM        Posts q
    INNER JOIN  Posts a         ON q.AcceptedAnswerId = a.Id
    WHERE       q.PostTypeId    = 1
    AND         q.OwnerUserId   <> a.OwnerUserId
),
pairsUnion (user1, user2, whoAnswered) AS (
    SELECT  userQ, userA, 'usr 2 answered'
    FROM    QandA_users
    UNION ALL
    SELECT  userA, userQ, 'usr 1 answered'
    FROM    QandA_users
)
SELECT
            'site://u/' + CAST(user1 AS NVARCHAR) + '|Usr ' + CAST(user1 AS NVARCHAR) AS [User 1]
            , 'site://u/' + CAST(user2 AS NVARCHAR) + '|Usr ' + CAST(user2 AS NVARCHAR) AS [User 2]
            , COUNT(*)  AS [Reciprocal Q&A's]
FROM        pairsUnion
GROUP BY    user1
            , user2
HAVING COUNT (DISTINCT whoAnswered) > 1
ORDER BY    [Reciprocal Q&A's] DESC
            , user1
            , user2

Enter Parameters

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