#查询student表中的所有学生信息
select *
from student;
#查询student表中所有学生的姓名以及年龄
select Sname, Sage
from student;
#查询学生表中所有年龄大于等于19岁的学生年龄和姓名
select Sage,Sname
from student
where Sage >= 19;
#查询教师表中所有工资少于1500元或者工资大于2000元, 并且是03系的教师姓名
# and的优先级大于or???
select Tname, Salary, Dno
from teacher
where (Salary < 1500 or Salary > 2000) and Dno = "03";
去重
#查询:或者学过001号课程, 或者学过002号课程的 学生学号(使用distinct去重)
select distinct Sno
from sc
where Cno in ("001", "002");
模糊查询
#查询: 既学过001号课程, 又学过002号课程的 学生学号
# 一表连接(取别名)
#查询: 既学过001号课程, 又学过002号课程的 学生学号
select sc1.Sno no
from sc sc1,
sc sc2
where sc1.Cno = '001'
and sc2.Cno = '002'
and sc2.Sno = sc1.Sno;
#查询: 所有姓张的学生学号及姓名
select Sno,Sname
from student
where Sname like "张%";
#查询: 所有张某某的学生学号和姓名
#MOOC上说一个汉字占两个字符, 所以需要四根下划线, 可实际执行一个汉字对应一根下划线
select Sno,Sname
from student
where Sname like "张_";
#查询: 所有不姓张的同学的姓名
select Sno,Sname
from student
where Sname not like "张%";