Created
February 22, 2023 22:51
-
-
Save Xevion/5a5f73f34839613f840390b1b014f338 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Find all threads that have zero subscriptions BUT have at least one attachment | |
SELECT * | |
FROM (SELECT "Thread".id, "Thread".subject, | |
COUNT(DISTINCT(S."threadId")) AS Subscriptions, | |
COUNT(A.id) AS Attachments | |
FROM "Thread" | |
LEFT JOIN "Post" P on "Thread".id = P."threadId" | |
LEFT JOIN "Attachment" A on P.id = A."postId" | |
LEFT JOIN "Subscription" S on "Thread".id = S."threadId" | |
GROUP BY "Thread".id) | |
AS COUNTS | |
WHERE COUNTS.Subscriptions = 0 AND COUNTS.Attachments > 1 | |
ORDER BY COUNTS.Attachments DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment