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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Generate student class position

Author  Topic 

Adura19
Starting Member

5 Posts

Posted - 2012-08-13 : 05:19:54
I have designed student database with tables: student, subjects and scores.
The scores table has fields; CA and EXAM.
How can i generate (1) average score per student
(2) position of student base on their average score.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-13 : 05:55:35
;with cte as
(
select student_id, avg_score = avg(EXAM)
from scores
group by student_id
)
select student_id, avg_score, position = rank() over (order by avg_score desc)
from cte


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Adura19
Starting Member

5 Posts

Posted - 2012-08-13 : 07:36:32
Thanks,it works
Go to Top of Page
   

- Advertisement -