+ 2

SQL Query: Find the topper among the three students from the given table.

stud_code subj_code Marks 1. 1. 80 1. 2. 70 2 1. 90 2. 2. 70 3. 1. 80 3. 2. 90

22nd Aug 2017, 10:27 AM
Lav Saini
Lav Saini - avatar
15 Respostas
+ 4
still wrong remove "where"
22nd Aug 2017, 6:12 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 3
i am glad i could help
22nd Aug 2017, 1:44 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 2
select * from table order by Marks, subj_code
22nd Aug 2017, 10:48 AM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 2
SELECT TOP 3 stud_code, (SUM(Marks)) as Total, (SUM(Marks)/COUNT(Marks)) as Average FROM table GRIUP BY stud_code ORDER BY Average DESC
22nd Aug 2017, 1:32 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 2
same code just add TOP n for your query you can do like this select top 6 stud_code, subj_code, marks from table order by marks desc, subj_code asc
22nd Aug 2017, 1:33 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 1
ok you want to add students marks and male the list from top to bottom one question do you want to count and her the average of just sum ???
22nd Aug 2017, 12:55 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 1
SELECT stud_code, (SUM(Marks)) as Total, (SUM(Marks)/COUNT(Marks)) as Average FROM table GRIUP BY stud_code ORDER BY Average DESC
22nd Aug 2017, 12:59 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 1
ohkk... thanks a lot
22nd Aug 2017, 1:42 PM
Lav Saini
Lav Saini - avatar
+ 1
select stud_code, sum(marks) as total , max(marks) from table group by marks, order by marks;
22nd Aug 2017, 6:36 PM
GOKUL KRISHNA YADAVA P
GOKUL KRISHNA YADAVA P - avatar
0
this one is according to the query... but what if the question demands only the topper's code and sum...?
22nd Aug 2017, 1:29 PM
Lav Saini
Lav Saini - avatar
0
select stud_code, sum(marks) as total , max(marks) from table where order by marks;
22nd Aug 2017, 2:21 PM
GOKUL KRISHNA YADAVA P
GOKUL KRISHNA YADAVA P - avatar
0
group by marks;
22nd Aug 2017, 4:46 PM
GOKUL KRISHNA YADAVA P
GOKUL KRISHNA YADAVA P - avatar
0
@Melih Melik Sonmez
22nd Aug 2017, 4:46 PM
GOKUL KRISHNA YADAVA P
GOKUL KRISHNA YADAVA P - avatar
0
oh yes u r right thnk u
22nd Aug 2017, 6:36 PM
GOKUL KRISHNA YADAVA P
GOKUL KRISHNA YADAVA P - avatar
- 1
@Melik Sonmez ... thanks for the ans... but the query is to show the topper's stud_code after adding total marks of each student and the taking the max of that... hope you now understood the problem i am having here...
22nd Aug 2017, 12:38 PM
Lav Saini
Lav Saini - avatar