Multiple Column Rankings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • corwin728
    New Member
    • Oct 2007
    • 3

    Multiple Column Rankings

    I was wondering with a table setup like this

    Name fish_sales cat_sales dog_sales
    Bob 5 10 3
    Mary 8 7 6
    Ken 10 8 7

    Is there a way to get a stack ranking for each column type without getting into temporary tables? The output would hopefully look like :

    Name f_sales f_rank c_sales c_rank d_sales d_rank
    Bob 5 3 10 1 3 3
    Mary 8 2 7 3 6 2
    Ken 10 1 8 2 7 1

    but would have more names then just those three. If you need any more info please let me know.
    Thanks
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    You can use case statement.
    Good Luck.

    Comment

    • Delerna
      Recognized Expert Top Contributor
      • Jan 2008
      • 1134

      #3
      what version of sql server are you using
      I ask because version 2005 has an row number function
      If you have 2005 then you could have 3 subqueries (1 for each animal) sorted in descending order with a field containing the row number

      then you could join the 3 subqueris by the salesperson

      I don't have 2005 so I cant provide an example
      Anyone else??

      Comment

      Working...