|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 2:42 PM
Points: 3,457,
Visits: 2,532
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
There are several ranking functions: RANK DENSE_RANK NTILE ROW_NUMBER
When the question asked will it always return consecutive integers, I knew right away that it was false because none of them will always return consecutive integers if there is only one row. One row is still a non empty rowset but that was not explained in the provided explanation.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 6:39 AM
Points: 9,376,
Visits: 6,472
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:23 AM
Points: 5,242,
Visits: 7,052
|
|
cengland0 (1/6/2011) When the question asked will it always return consecutive integers, I knew right away that it was false because none of them will always return consecutive integers if there is only one row. Meh, I could just as well say that everything is consecutive in a single-row rowset. According to http://www.thefreedictionary.com/consecutive, "consecutive" means (a.o.) "Following one after another without interruption" - and in a single row row-set, there can never be any interruption.
The reason that RANK does not return consecutive values is how ties are handled - for instance, if the RANK is based on the scores {9.6, 8.4, 9.6}, the results would be
Score Rank 9.6 1 9.6 1 8.4 3 Because two rows get the rank 1, the value 2 is skipped. That makes the values non-consecutive.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
Hugo Kornelis (1/6/2011)
[quote] cengland0 (1/6/2011)
Meh, I could just as well say that everything is consecutive in a single-row rowset. According to http://www.thefreedictionary.com/consecutive, "consecutive" means (a.o.) "Following one after another without interruption" - and in a single row row-set, there can never be any interruption. You forgot a major component of the definition of consecutive. The "one after another" part. When you have a one row rowset, how can you have one after another in the resultset? That means you must have a minimum of two rows to have one after another.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 6:39 AM
Points: 9,376,
Visits: 6,472
|
|
cengland0 (1/6/2011)
Hugo Kornelis (1/6/2011)
[quote] cengland0 (1/6/2011)
Meh, I could just as well say that everything is consecutive in a single-row rowset. According to http://www.thefreedictionary.com/consecutive, "consecutive" means (a.o.) "Following one after another without interruption" - and in a single row row-set, there can never be any interruption. You forgot a major component of the definition of consecutive. The "one after another" part. When you have a one row rowset, how can you have one after another in the resultset? That means you must have a minimum of two rows to have one after another.
If you really want to take it to a filosophical level, you could argue that one row comes after nothing.
How to post forum questions. Need an answer? No, you need a question. What’s the deal with Excel & SSIS?
Member of LinkedIn. My blog at LessThanDot.
 MCSA SQL Server 2012 - MCSE Business Intelligence
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 7:13 AM
Points: 6,370,
Visits: 8,233
|
|
cengland0 (1/6/2011) There are several ranking functions: RANK DENSE_RANK NTILE ROW_NUMBER Yes, there are several. However, this question is about the RANK() function, so why even bring these others into the mix?
When the question asked will it always return consecutive integers, I knew right away that it was false because none of them will always return consecutive integers if there is only one row. One row is still a non empty rowset but that was not explained in the provided explanation.
Are you just trying to find fault with the question?
A better argument would have been that all of the windowing functions accept a PARTITION BY clause, which re-starts the numbering - thus the results are not always sequential.
However, sometimes you just have to go with what you know the author meant to convey.
Wayne Microsoft Certified Master: SQL Server 2008 If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it! Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines, CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
WayneS (1/6/2011)
Yes, there are several. However, this question is about the RANK() function, so why even bring these others into the mix? Because I usually have to look them up to make sure I'm using the right one. But in this case, I didn't have to look anything up because none of them would return consecutive integers (when there is a one-row result).
Are you just trying to find fault with the question?
Not necessarily. I do work for a very large company, in the training organization, and would consider myself an expert on quizzes.
There have been cases of companies firing employees during training for failing tests. To avoid legal issues, you better look at each question carefully to make sure the answer they selected can never be a correct answer. For this reason, I am always looking at these QOTD's with a different eye than a regular person.
In a previous company, I have been involved in the process of firing and disciplinary actions of employees not passing tests. I've also had to gather supporting documentation to take to court when an ex-employee took legal action.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
Another way to put this is if the question said:
In a non-empty rowset, ROW_NUMBER() always returns consecutive integers.
What would you answer? True or False?
I'd still answer False because it's possible to have a one-row rowset but the author is probably thinking True.
I did get the answer for this QOTD correct.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 8:23 AM
Points: 5,242,
Visits: 7,052
|
|
cengland0 (1/6/2011) Another way to put this is if the question said:
In a non-empty rowset, ROW_NUMBER() always returns consecutive integers.
What would you answer? True or False?
I'd still answer False because it's possible to have a one-row rowset but the author is probably thinking True. I guess I'd first check to see if you are the author of that question ;)
But had I seen such a question before today, then I think there's about 80% chance I'd have replied True. If the correct answer had been False because of PARTITION BY, I would have slapped myself on the forehead and complimented the question's author. If the correct answer had been False because of a single-row rowset "not being consecutive", I would have felt misled and cheated.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|