Skip to content

Instantly share code, notes, and snippets.

@ryancole
Created April 29, 2015 18:56
Show Gist options
  • Save ryancole/53449a13e3c38b763319 to your computer and use it in GitHub Desktop.
Save ryancole/53449a13e3c38b763319 to your computer and use it in GitHub Desktop.
WITH RankedMonthlySizes AS
(
SELECT Matter_MatterId AS MatterId,
HostingFilesize,
DENSE_RANK() OVER (PARTITION BY Matter_MatterId ORDER BY MonthAndYear DESC) AS DateRank
FROM dbo.RelativityMatterFilesizes
)
SELECT s.MatterId, s.HostingFilesize
FROM RankedMonthlySizes AS s
JOIN dbo.Matters AS m ON m.MatterId = s.MatterId
WHERE s.DateRank = 1 AND (m.InRelativity = 1 AND (m.IsHibernated != 1 AND m.IsHidden != 1) AND m.RelativityArtifactId IS NOT NULL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment