iv, contr

0

Please login or register to vote for this query.

(click on this box to dismiss)

Drupal Answers Meta

Q&A about the site for Drupal developers and administrators

Select myuser.Id, 
Reci.ReceviedReci,
Badge.EarnedBadge
FROM
(
SELECT u.Id FROM Users u WHERE u.Id = ##UserId##
) as myuser
LEFT JOIN (
  SELECT Question.OwnerUserId, COUNT(Answer.Id) AS ReceviedReci
    FROM (SELECT p.OwnerUserId, p.Id
          FROM Posts p
          WHERE p.PostTypeId = 1 AND p.OwnerUserId = ##UserId##) AS Question
    INNER JOIN (SELECT *
          FROM Posts p
          WHERE p.PostTypeId = 2
          AND (p.CreationDate <= '##Date?2021-10-01##')) AS Answer
          ON Question.Id = Answer.ParentId
  GROUP BY Question.OwnerUserId
) AS Reci ON myuser.Id = Reci.OwnerUserId
LEFT JOIN (
  SELECT b.UserId, COUNT(b.Id) AS EarnedBadge
  FROM Badges b
  WHERE b.UserId = ##UserId##
  AND b.Date <= '##Date?2021-10-01##'
  GROUP BY b.UserId
) AS Badge ON myuser.Id = Badge.UserId

Enter Parameters

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