Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
zhangrundatd
Starting Member
2 Posts |
Posted - 2006-04-12 : 02:31:47
|
I want to obtain the top 1 students' name in each grade,but this code dosen't work: select top 1 name from student group by grade order by GPA desc Can anyone tells me what to do? |
|
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2006-04-12 : 03:15:51
|
| SELECT *FROM DoYourOwnHomework |
 |
|
|
a_r_satish
Yak Posting Veteran
84 Posts |
Posted - 2006-04-12 : 03:26:15
|
| Something like this...create table [dbo].[stud](name varchar(5),grade char(1),gpa int)insert into stud values('sat','a',85)insert into stud values('bat','a',82)insert into stud values('cat','a',78)insert into stud values('hat','b',81)insert into stud values('mat','b',87)insert into stud values('pat','c',70)insert into stud values('tat','c',78)select Max(Name) Name,grade, Max(gpa) gpa from stud Group by grade satish.r"Way to success is always under Construction" |
 |
|
|
zhangrundatd
Starting Member
2 Posts |
Posted - 2006-04-12 : 03:33:51
|
| Thanks a_r_satish a lot.I'll have a try. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
TheKing
Starting Member
1 Post |
Posted - 2006-04-12 : 12:31:24
|
| try this:select Distinct Student.name, Max(grade) as T from studentgroup by (name) order by (T); |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-04-12 : 12:37:10
|
quote: Originally posted by TheKing try this:select Distinct Student.name, Max(grade) as T from studentgroup by (name) order by (T);
No need to use Distinct MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|