all groups > sql server misc > august 2003 >
You're in the

sql server misc

group:

problem


Re: problem sampangi
8/19/2003 8:10:11 PM
sql server misc:
Try

Create table #temptable1 (student int,exam varchar(4),grade tinyint)
INSERT #temptable1 Values(1,'math', 90)
INSERT #temptable1 Values(1,'chem', 89)
INSERT #temptable1 Values(1,'phys', 88)
INSERT #temptable1 Values(1,'his' , 88)
INSERT #temptable1 Values(1,'Geo' , 85)
INSERT #temptable1 Values(2,'math', 89)
INSERT #temptable1 Values(2,'chem', 84)
INSERT #temptable1 Values(2,'phys', 83)
INSERT #temptable1 Values(2,'Geo' , 81)
INSERT #temptable1 Values(3,'Lit' , 80)
INSERT #temptable1 Values(3,'GYM' , 79)


SELECT *
FROM #temptable1 AS s1
WHERE grade in ( SELECT TOP 3 grade FROM #temptable1 AS s2
WHERE s1.student = s2.student order by grade desc)


HTH,
Srinivas Sampangi

"mail4u9999@yahoo.com " <u489685058@spawnkill.ip-mobilphone.net> wrote in
message news:l.1061345122.1412902832@[63.127.215.130]...
[quoted text, click to view]

problem u489685058 NO[at]SPAM spawnkill.ip-mobilphone.net
8/20/2003 2:05:21 AM
it won't quite work.


student exam grade
1 math 90
1 chem 89
1 phys 88
1 his 88
1 Geo 85
2 math 89
2 chem 84
2 phys 83
2 Geo 81
3 Lit 80
3 GYM 79

3 highest:

1 math 90
1 chem 89
1 phy 88
1 his 88
2 math 89
2 chem 84
2 phys 81
3 lit 80
3 gym 79

SELECT *
FROM #temptable1 AS s1
WHERE ( SELECT COUNT( * ) FROM #temptable1 AS s2
WHERE s1.student = s2.student And s1.exame <= s2.exame ) <= 3
GROUP BY student, exam, grade
ORDER BY s1.student;




--
Sent by mail4u9999 from yahoo part of com
This is a spam protected message. Please answer with reference header.
AddThis Social Bookmark Button