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 6079013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:53:54+00:00 2026-05-23T10:53:54+00:00

Possible Duplicate: sql to select top 10 records Assuming you have one table with

  • 0

Possible Duplicate:
sql to select top 10 records

Assuming you have one table with StuId, StuName, Subject, Grade. You are required to provide a subquery to return a list of honor students (top 10 percent), sorted by their grade point average.

for example, if I have 10 student whose average grade is 100,90,80,…10.
It is required to output the first student name whose average is 100. Only one student grade is output. So I can’t use limit 10

I am using mysql 5.1.

Here is my query:

SELECT Stuname, TOP 10 Avg(Grade) as GPA 
  FROM Table 
GROUP BY Stuid 
ORDER BY GPA

The query is not correct because of the TOP 10. Checking MYSQL 5.1 reference, it does not support top 10.

According to comments, I dont think it can be resolved using one query, so I come up with a method:

F(conn){
Statement stmt;
int top10percnet = 0;
try{
stmt = conn.createStatement;
String query = "select CEIL(count(stuname)*10/100) as 10percent from grades";
ResultSet rs = stmt.execute(query);
while(rs.next()){
  top10percent = rs.getString("10percent");
}
query = "select stuname, avg(grade) as average from grades group by stuname order
by average desc limit " + Integer.toString(top10percnet);
rs=stmt.execute(query);
while(rs.next()){
   ...// output result
}
}
catch(SQLException e){
}



}  
  • 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-05-23T10:53:55+00:00Added an answer on May 23, 2026 at 10:53 am
    count = select CEIL(count(Stuname)*10/100) from table_name;
    select Stuname from table_name ORDER BY GPA DESC limit count;
    

    First query will return the 10% of the students.CEIL is used to convert it into integer.
    Second query is to retrieve the data.
    The count calculated from the first query is set as the limit to the second query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: SQL Query to Select First/Top N records Here is my code so
Possible Duplicate: SQL - find records from one table which don't exist in another
Possible Duplicate: Select n random rows from SQL Server table I have database and
Possible Duplicate: SQL Server: Only last entry in GROUP BY I have a table
Possible Duplicate: How to select the nth row in a SQL database table? I
Possible Duplicate: SQL query to find Missing sequence numbers I have a table which
Possible Duplicate: dynamic sql pivot in sql server I have a table called Col_values
Possible Duplicate: Subtraction in sql statement I have a table with Presidents names and
Possible Duplicate: SQL Server - use a parameter to select the top X of
Possible Duplicate: SQL: Find the max record per group I have a table with

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.