Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:13:57+00:00 2026-06-17T09:13:57+00:00

How to select Top 40% from a table without using the Top clause (or

  • 0

How to select Top 40% from a table without using the Top clause (or Top percent, the assignment is a little ambiguous) ? This question is for T-SQL, SQL Server 2008. I am not allowed to use Top for my assignment.

Thanks.

This is what I’ve tried but seems complicated. Isn’t there an easier way ?

select top (convert (int, (select round (0.4*COUNT(*), 0) from MyTable))) * from MyTable
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:13:57+00:00Added an answer on June 17, 2026 at 9:13 am

    A problem with the NTILE(10) answers given so far is that if the table has 15 rows they will return 8 rows (53%) rather than the correct number to make up 40% (6).

    If the number of rows is not evenly divisible by number of buckets the extra rows all go into the first buckets rather than being evenly distributed.

    This alternative (borrows SQL Menace’s table) avoids that issue.

    WITH CTE
         AS (SELECT *,
                    ROW_NUMBER() OVER ( ORDER BY Score) AS RN,
                    COUNT(*) OVER()                     AS Cnt
             FROM   #temp)
    SELECT StudentID,
           Score
    FROM   CTE
    WHERE  RN <= CEILING(0.4 * Cnt )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql like this: SELECT TOP 1 field_name * FROM table_name and
I'm trying to convert this SQL query to L2S.. SELECT TOP 5 vt.* FROM
I'm using a SELECT statement in T-SQL on a table similar to this: SELECT
Normally I would do select top (1) * from table where id active =
Can this MS-Access query be improved? i.e. the SELECT TOP 1 col FROM Table2
My current method is this: SELECT TOP 1 ID FROM DATAENTRY ORDER BY ID
What does TOP 1 mean in an sql query? SELECT TOP 1 RequestId FROM
I'd like to reproduce the following SQL into C# LinqToSql SELECT TOP(10) Keywords.* FROM
I'm running this query: SELECT TOP 1 [DVD Copy].[Stock No] FROM [DVD Copy] WHERE
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.