學(xué)生表名為:student, 單科成績(jī)的字段為:subject。學(xué)生名字為:name 查詢單科成績(jī)前十:
mysql語(yǔ)句為:
select * from student order by subject desc limit 10; 查詢總分成績(jī)前十:mysql語(yǔ)句為:
select sum(subject) subject,name from student group by name order by subject desc limit 10; 注: select sum(subject) subject,name 這句的意思是:sum(subject) subject 把單科成績(jī)加總用subject 來(lái)命名(就是總成績(jī)),name就是一個(gè)字段,這里只有兩個(gè)字段。 group by name order by subject : group by name 的意思按照名字這一欄來(lái)分組,當(dāng)然,學(xué)生成績(jī)表名字有可能是一樣的,按照學(xué)號(hào)是最準(zhǔn)確的,這里只是舉個(gè)例子。
order by subject 這句的意思是按照總分成績(jī)排序,這里的subject 是前面重命名總分的意思。
select sum(subject) as countsubject,name from student group by name order by countsubject desc limit 10;