| Author |
Topic  |
|
|
Prosercunus
Starting Member
USA
22 Posts |
Posted - 10/09/2012 : 18:18:43
|
I have a student table with a sname (Student Name) and a gpa (GPA) columns.
I need to sort or find the lowest GPA of the bunch so I...
SELECT sname, MIN(gpa) as "Lowest GPA" FROM Student Group By sname
However it should only be showing the one student with a 0.00 GPA, but instead it is showing all of the students and all of the GPA
I also can never do MIN(gpa) or AVG(GPA) since GPA is not set as an Integer and does not work as such. |
Edited by - Prosercunus on 10/09/2012 18:37:45
|
|
|
chadmat
The Chadinator
USA
1961 Posts |
Posted - 10/09/2012 : 19:10:54
|
You are not asking for a single student with the Min GPA, you are asking for the Student in each group who has the Min GPA. If you want the single lowest GPA you need:
SELECT sname, gpa as "Lowest GPA" FROM Student WHERE gpa = (SELECT MIN(gpa) FROM Student)
-Chad |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47173 Posts |
Posted - 10/09/2012 : 21:23:44
|
SELECT TOP 1 WITH TIES sname,gpa
FROM table
ORDER BY gpa ASC
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
chadmat
The Chadinator
USA
1961 Posts |
Posted - 10/10/2012 : 01:18:04
|
quote: Originally posted by visakh16
SELECT TOP 1 WITH TIES sname,gpa
FROM table
ORDER BY gpa ASC
Ahh, even better ------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47173 Posts |
Posted - 10/10/2012 : 01:58:02
|
quote: Originally posted by chadmat
quote: Originally posted by visakh16
SELECT TOP 1 WITH TIES sname,gpa
FROM table
ORDER BY gpa ASC
Ahh, even better ------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
tnx 
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
Prosercunus
Starting Member
USA
22 Posts |
Posted - 10/10/2012 : 04:08:17
|
You guys are great. I see exactly how that is done.
I tried doing this same thing with AVG and it didn't exactly work out as well. some further digging it seems newer SQL server doesn't let you do this? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47173 Posts |
Posted - 10/10/2012 : 23:50:41
|
do you mean this?
SELECT TOP 1 WITH TIES sname,AVG(gpa) AS avggpa
FROM table
GROUP BY sname
ORDER BY avggpa ASC
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|