April 2, 2012 at 8:33 am
Hi folks,
This is an excerpt from a piece of old code I'm dealing with:
RANK() OVER (PARTITION BY a.[Id]
a.[operatorId]
a.[Linje]
a.[ArrDep]
ORDER BY COUNT(9) DESC) AS [Rank]
What does the 9 in the COUNT(9) stand for? What does that do for the ranking ?
Best Regards,
Jonas
April 2, 2012 at 8:52 am
That is ordering by the count of rows. Not sure why 9 was chosen. It could just as easily be count(*).
--edit totally misread this post the first time. 😀
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 2, 2012 at 9:05 am
To illustrate the differences try this code
USE Northwind
GO
SELECT COUNT(4) AS 'Count by col number' FROM dbo.Audit -- counts nulls
SELECT COUNT(Item) AS 'count specific col' FROM dbo.Audit --counts only non null values
SELECT COUNT(*) AS 'Count *' FROM dbo.Audit
Results:
Count by col number
-------------------
21
count specific col
------------------
9
Warning: Null value is eliminated by an aggregate or other SET operation.
Count *
-----------
21
April 2, 2012 at 9:42 am
Thought so. It doesn't seem to change the result if I elaborate with changing the '9' to a '1', '0' or '77777' (or '*'). 🙂
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply