数据库,知识点汇总

查询一列:
select tno * from score --- 来自score表的tno列


-- 查询Score表中成绩为60,61或62的记录。
select * from score where degree=60 or degree=61 or degree=62
select * from score where degree in (60,61,62)
in 是说明 degree在()里面


以Cno升序、Degree降序查询Score表的所有记录。
select * from score order by cno asc , degree desc


查询“95031”班的学生人数。
select COUNT(*) from Student where class='95031'
select COUNT(Class) from Student where class='95031'
可以写 * ,也可以是class


查询每门课的平均成绩。
select cno,avg(degree) from Score group by cno


查询所有学生的Sname、Cname和Degree列。
select t1.Sname,t3.Cname,t2.Degree
from Student t1
join Score t2 on t1.Sno=t2.Sno
join Course t3 on t2.Cno = t3.Cno

三个表的链接,表1和表2 相同的是 sno , 链接表3的时候,找与之相同的项即可

原文地址:https://www.cnblogs.com/yunpeng521/p/7060019.html