The Ranking Function

  • Comments posted to this topic are about the item The Ranking Function

  • Can anyone think of any real life examples where you'd want to rank over something non-unique?

  • Toreador wrote:

    Can anyone think of any real life examples where you'd want to rank over something non-unique?

    Yes.  Sales by salesman, salary.  I once had a query that ranked truck drivers by many categories individually - miles driven, loads, total revenue, revenue per mile, etc.

  • Toreador wrote:

    Can anyone think of any real life examples where you'd want to rank over something non-unique?

     

    Sure, this is pretty common when you use it with a meaningful order by.  A common example might be something like top sales rep per day, partition by day and order by number of sales.

  • Toreador wrote:

    Can anyone think of any real life examples where you'd want to rank over something non-unique?

    Heh... along with what the others posted, another possible answer is "Interview Question" 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Great question, Steve.

    Another hint here is that there's nothing to guarantee the order within any given rank.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Of course, changing the function to DENSE_RANK() and the answer changes to "2 - Lenovo & Samsung".

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply