I\'m looking get two things from a query, given a set of contraints:
I can get the first ma
Assuming you are using a newish version of SQL Server (2008+ from memory) then you can use analytic functions.
Simplifying things somewhat, they are a way of way of doing an aggregate over a set of data instead of a group - an extension on basic aggregates.
Instead of this:
SELECT ... , COUNT(*) as MatchCount FROM Table WHERE ...
You do this:
SELECT ... , COUNT(*) as MatchCount OVER (PARTITION BY
ORDER BY ) FROM Table WHERE ... GROUP BY
Without actually running some code, I can't recall exactly which aggregates that you can't use in this fashion. Count is fine though.