Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    37

    Unanswered: Difference between top with ties and percentage with ties

    hi
    what is the difference between "top 5 percent with ties" and
    "top 5 percent with ties"

    Thaks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by bandiramireddy View Post
    between "top 5 percent with ties" and "top 5 percent with ties"
    nothing
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I'm guessing you actually meant "top 5 with ties" and "top 5 percent with ties"...
    Either way it is hard to explain without using the words in the statements themselves!


    TOP N = the first N rows of your resultset based on the ORDER BY clause
    TOP N PERCENT = the first N percent of rows of your resultset based on the ORDER BY clause

    WITH TIES = If the N and N + 1 rows have the same values, show them both (they are equivalent).

    This might be better explained with an example...
    Code:
    DECLARE @x table (
       x tinyint
    )
    
    INSERT INTO @x (x)
              SELECT 1
    UNION ALL SELECT 2
    UNION ALL SELECT 2
    UNION ALL SELECT 3
    
    SELECT TOP 2
           x As "Top 2"
    FROM   @x
    ORDER
        BY x
        
    SELECT TOP 2 WITH TIES
           x As "Top 2 with ties"
    FROM   @x
    ORDER
        BY x
    
    SELECT TOP 50 PERCENT
           x As "Top 50%"
    FROM   @x
    ORDER
        BY x
    
    SELECT TOP 50 PERCENT WITH TIES
           x As "Top 50% with ties"
    FROM   @x
    ORDER
        BY x
    Results
    Code:
    Top 2
    -----
    1
    2
    
    (2 row(s) affected)
    
    Top 2 with ties
    ---------------
    1
    2
    2
    
    (3 row(s) affected)
    
    Top 50%
    -------
    1
    2
    
    (2 row(s) affected)
    
    Top 50% with ties
    -----------------
    1
    2
    2
    
    (3 row(s) affected)
    Hope this helps!
    George
    Home | Blog

  4. #4
    Join Date
    Jul 2010
    Location
    ISHHHH
    Posts
    130
    nice its very easy to understand
    WiTh Tnks & ReGaRdS
    mAtHuKuMaLi

Posting Permissions

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