mysql显⽰所有表_mysql中⼀张学⽣表,查询出单科成绩前⼗名学⽣的所有信息和总分成绩。。。
展开全部
学⽣表名为:62616964757a686964616fe59b9ee7ad9431333366306564student, 单科成绩的字段为:subject。学⽣名字为:name
查询单科成绩前⼗:mysql语句为:lect * from student order by subject desc limit 10;
查询总分成绩前⼗:mysql语句为:lect sum(subject) subject,name from student group by name order by subject desc limit 10;
注:
lect sum(subject) subject,name
这句的意思是:sum(subject) subject 把单科成绩加总⽤subject 来命名(就是总成绩),name就是⼀个字段,这⾥只有两个字段。
group by name order by subject : group by name 的意思按照名字这⼀栏来分组,当然,学⽣成绩表名字有可能是⼀样的,按照学号是最准确的,这⾥只是举个例⼦。芹菜炒肉丝的做法
order by subject 这句的意思是按照总分成绩排序,这⾥的subject 是前⾯重命名总分的意思。
lect sum(subject) as countsubject,name from student group by name order by countsubject desc limit 10;
学⽣成绩表常⽤sql
1. 在表中插⼊符合主键
张爱玲传奇[sql]
/*成绩表*/
CREATE TABLE SC
(
Sid INT REFERENCES Student(Sid), /*学⽣学号*/
Cid INT REFERENCES Cour(Cid), /*课程编号*/
Score INT NOT NULL, /*课程分数*/
PRIMARY KEY(Sid,Cid) /*将学⽣学号和课程编号设为复合主键*/
)
2. 查询各科成绩最⾼分,最低分以及平均分
[sql]
SELECT , MAX() AS Max, MIN() AS Min, AVG() AS Average
FROM Cour c JOIN SC s ON c.Cid = s.Cid
GROUP BY
/
*此处应注意,若不按照进⾏分组,SQL语句会报错,在SELECT语句中不合法,因为它并未出现在聚合函数中也没有出现在GROUP BY 语句中*/姜白石
3. 查询平均成绩⼤于80分的学⽣姓名以及平均成绩
[sql]
SELECT Sname, AVG(Score) AS Average FROM Student JOIN SC
ON Student.Sid=SC.Sid
GROUP BY Sname
HAVING AVG(Score)>80
/*以聚合函数为条件进⾏删选只能在HAVING语句中进⾏,WHERE语句不⽀持聚合函数*/
4. 按总分为学⽣排名,总分相同名次相同
[sql]
SELECT RANK() OVER (ORDER BY SUM(s) DESC) AS Rank, ,
节电手抄报
猪崽
ISNULL(SUM(s),0)
FROM Student s LEFT JOIN SC ss
ON s.Sid = ss.Sid初一上册语文作文
少先队员宣誓词
GROUP BY
ORDER BY SUM(s) DESC
掰手腕比赛/*RANK()是SQL Server的⼀个built-in函数,语法为
RANK() OVER ( [ partition_by_clau ] order_by_clau ).*/
5. 查询总分在100⾄200之间的学⽣姓名及总分
[sql]
SELECT ,SUM(s) FROM Student s JOIN SC ss ON s.Sid=ss.Sid
GROUP BY HAVING SUM(s) BETWEEN 100 AND 200