天天看點

mysql查詢學生_在mysql中查詢學生排名

select stu_name,zongchengji from findstudentcourse_view where c_status='期中'

我用以上語句查詢學生姓名和學生成績,資料如下:

stu_name  zongchengji

aa           456

ab           487

bb           530

cc            497

dd           512

我想通過以下的查詢得到學生姓名、成績、已經成績排名,可是沒有效果

select stu_name,zongchengji,(select count(*) from findstudentcourse_view where c_status='期中' and zongchengji >=(select zongchengji from findstudentcourse_view where c_status='期中' )) as rank from findstudentcourse_view

如果希望有技術的同僚,幫個忙,不勝感激

問題補充

此問題已經被我自己解決掉了,答案如下:

select c.stu_name,c.zongchengji,(select count(*) from findstudentcourse_view where c.zongchengji<=zongchengji  and c_status='期中')  as paiming from findstudentcourse_view c  where c.c_status='期中'