Query help
Posted: Mon 12 Oct 2015 23:09
Table that has the following as part of the columns:
Table X
FirstName | LastName | Score1 | Score2 | TotalScore | Grade
John | Doe | 101 | 102 | 203 | 10
Mary | Moe | 111 | 112 | 223 | 10
Herb | Garden | 121 | 122 | 243 | 9
Terry | Terrance | 131 | 132 | 263 | 10
John | Foe | 91 | 92 | 183 | 10
I'm trying to do a descending sort based on either score 1 or score 2 or total score within a certain grade, which isn't difficult. But what I'm trying to do is have a place column added, so that results show 1st, 2nd, 3rd, etc.
So looking for the top total scores for 10th graders, I could do a:
select FirstName, LastName, TotalScore where grade=10 order by TotalScore DESC
Would give me:
Terry Terrance 263
Mary Moe 223
John Doe 203
John Foe 183
I would like have a place number too, which would need to be calculated:
1 Terry Terrance 263
2 Mary Moe 223
3 John Doe 203
4 John Foe 183
Any suggestions?
Thanks!
Lance
Table X
FirstName | LastName | Score1 | Score2 | TotalScore | Grade
John | Doe | 101 | 102 | 203 | 10
Mary | Moe | 111 | 112 | 223 | 10
Herb | Garden | 121 | 122 | 243 | 9
Terry | Terrance | 131 | 132 | 263 | 10
John | Foe | 91 | 92 | 183 | 10
I'm trying to do a descending sort based on either score 1 or score 2 or total score within a certain grade, which isn't difficult. But what I'm trying to do is have a place column added, so that results show 1st, 2nd, 3rd, etc.
So looking for the top total scores for 10th graders, I could do a:
select FirstName, LastName, TotalScore where grade=10 order by TotalScore DESC
Would give me:
Terry Terrance 263
Mary Moe 223
John Doe 203
John Foe 183
I would like have a place number too, which would need to be calculated:
1 Terry Terrance 263
2 Mary Moe 223
3 John Doe 203
4 John Foe 183
Any suggestions?
Thanks!
Lance