473,473 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sql query to find topper in a class

6 New Member
hi...
i need the solution 4r this, in code some mistake is there, it has to print the topper of the class and his name. and also it should print two persons, if two of them got top marks. But i am not getting it
if any one can do this kindly help me.........

this is my code:

Expand|Select|Wrap|Line Numbers
  1. select max(c.m) max
  2. from (select avg(marks)as m,stdid
  3. from student2
  4.  group by stdid
  5. )c
  6. inner join
  7. (select avg(marks)as m,stdid
  8. from student2
  9. group by stdid)d
  10. on c.stdid= d.stdid;
Feb 5 '08 #1
4 7772
amitpatel66
2,367 Recognized Expert Top Contributor
hi...
i need the solution 4r this, in code some mistake is there, it has to print the topper of the class and his name. and also it should print two persons, if two of them got top marks. But i am not getting it
if any one can do this kindly help me.........

this is my code:

select max(c.m) max
from (select avg(marks)as m,stdid
from student2
group by stdid
)c
inner join
(select avg(marks)as m,stdid
from student2
group by stdid)d
on c.stdid= d.stdid;
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT stdid, mrk FROM
  3. (SELECT stdid, mrk, RANK() OVER(ORDER BY mrk desc) rnk FROM (SELECT stdid,AVG(marks) as mrk FROM student2 GROUP BY stdid ORDER BY mrk desc)) WHERE rnk = 2
  4.  
  5.  
Feb 5 '08 #2
mwasif
802 Recognized Expert Contributor
Hi jhansi,

Welcome to TSDN!!!

Kindly use proper tags when posting code.
Feb 7 '08 #3
jhansi
6 New Member
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT stdid, mrk FROM
  3. (SELECT stdid, mrk, RANK() OVER(ORDER BY mrk desc) rnk FROM (SELECT stdid,AVG(marks) as mrk FROM student2 GROUP BY stdid ORDER BY mrk desc)) WHERE rnk = 2
  4.  
  5.  
thank u for ur response.........


jhansi.
Feb 8 '08 #4
amitpatel66
2,367 Recognized Expert Top Contributor
thank u for ur response.........


jhansi.
You are welcome :)

MODERATOR
Feb 8 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
1
by: Sue | last post by:
I have a large training database that contains many records of future training courses. For a course there could be only one class or multiple classes. Where there are multiple classes, each class...
1
by: nilsonj | last post by:
Trying to set up an admin page for an online training registration page. I am having trouble with a sql statement. Here is the info on the tables. I have two tables: classPerson and reglist ...
4
by: Michael | last post by:
Hi, If I have R(a integer PRIMARY KEY, b text, c text, d integer); and I want to find how many different entries there are, (specified using b and c instead of a), is "select count(distinct b||c)...
6
by: Dixie | last post by:
I have asked this question before, but I could not get the suggested solution work. So I will give more details this time. I have an append query that adds several hundred records to a table...
1
by: Oliver Bleckmann | last post by:
Damn, what's wrong here? CGI cgi; map<string,stringcgiParam = cgi.analyseCgiParam(); cout << cgiParam << endl; cout << cgiParam << endl; /////////////////////// #include <iostream>
3
by: Phil Stanton | last post by:
I have a number of queries which use code for the output of 1 or more fields. For example Address:GetAddress(AddressID, True, 60) Address ID Points to an Address in a table - Address Line1, Line...
8
siridyal
by: siridyal | last post by:
I have a wholesale website that i'm working on that shows hundreds of items that are updated from time to time. These items are kept in a mysql database with several tables. I want to let the...
1
osward
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >=...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.