June 28, 2010 at 10:04 am
priya__ (6/28/2010)
Thanks all for your reply,I cannot use SUM as I am counting a Key column here and if I use sum it will sum up the columne instead...
I have to use count only...
You can use both.
COUNT with a preaggregate, SUM the COUNTS with a final aggregate, as shown.
Commonly done with cross-tabs/pivots, see this[/url] excellent paper.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
June 28, 2010 at 10:04 am
You can use sum because, if you check the code that Gianluca posted, you're summing 1 or 0, 1 if that row is to be counted, 0 if it's not to be counted. Try it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 16 through 16 (of 16 total)
You must be logged in to reply to this topic. Login to reply