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 |
|
roshana
Starting Member
31 Posts |
Posted - 2009-10-26 : 02:25:26
|
| Hi All I have to find out 2nd highest in a group.Subject Student MarkPhysics ABC 48Physics BCD 47Physics XYZ 43Maths ABC 40Maths BCD 49Maths XYZ 45Chemistry ABC 47Chemistry BCD 44Chemistry XYZ 49Here i have to find out students who got second rank in different subjectExp Ans Physics BCD 47Maths XYZ 45Chemistry ABC 47ThanksRoshan |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-26 : 02:27:53
|
[code]select *from( select *, rank = rank() over (partition by Subject order by Mark desc) from yourtable) rwhere rank = 2[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
roshana
Starting Member
31 Posts |
Posted - 2009-10-26 : 02:31:59
|
| Thanks KhtanIt is working fineThanksRoshan |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
kbhere
Yak Posting Veteran
58 Posts |
Posted - 2009-11-19 : 08:28:20
|
| You can try this.. This is query is for finding nth maximum...SELECT t1.mark FROM table AS t1WHERE n = (SELECT COUNT(*) FROM table AS t2 WHERE t1.mark >= t2.mark GROUP BY subject)Here, table -> your table namen -> position(if u want 2nd position you mentioned it as 2)Balaji.K |
 |
|
|
|
|
|