Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post

    SQL Server Union Problem

    I'm trying to do a 16 query union to get the ranks of teams in different statistics, heres an excerpt from the query

    Code:
    select team,row_number() over (order by pts desc) from team  where  year = 2010 
    UNION
    select team,row_number() over (order by opts asc) from team where year = 2010 
    UNION
    select team,row_number() over (order by offeff desc) from team where year =2010 
    UNION
    select team, row_number() over (order by defeff asc) from team where year = 2010
    This executes properly, but the results table is grouped by team (this is desirable) and then subgrouped by the row_number() ascending, meaning that I have no way of telling which row came from which query. How could I get it so that the order I query the row_number()'s in is the order in which they appear in the output.

  • #2
    New Coder
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post
    solved myself, just used union all and its a workable solution, sorry for posting!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •