Last active
August 29, 2015 14:15
-
-
Save ryancole/383e34f44297a9462215 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
-- original query without the aggregation | |
SELECT o.OpinionDocumentId, | |
o.DisplayTitle, | |
o.Date | |
FROM dbo.OpinionDocumentOpinionDocuments c | |
JOIN dbo.OpinionDocuments o ON o.OpinionDocumentId = c.OpinionDocument_OpinionDocumentId | |
WHERE c.OpinionDocument_OpinionDocumentId1 = 617143 | |
-- adjusted query with aggregation sub-query | |
-- can this query be improved? | |
SELECT o.OpinionDocumentId, | |
o.DisplayTitle, | |
o.Date, | |
(SELECT COUNT(1) | |
FROM dbo.OpinionDocumentOpinionDocuments | |
WHERE OpinionDocument_OpinionDocumentId1 = o.OpinionDocumentId) AS CitedByCount | |
FROM dbo.OpinionDocumentOpinionDocuments c | |
JOIN dbo.OpinionDocuments o ON o.OpinionDocumentId = c.OpinionDocument_OpinionDocumentId | |
WHERE c.OpinionDocument_OpinionDocumentId1 = 617143 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment