1、 查询student表的所有数据。
select * from student;
查询student表的所有数据。
2、 查询student表中sname、ssex。
select sname,ssex from student;
查询表中sname与ssex字段。
3、 查询教师所有的单位即不重复的depart列。
select depart from teacher GROUP BY depart;
group by depart:根据 depart 分组 查询 depart
4、 查询score表中成绩在60到80之间的所有记录。
select * from score where score >= 60 and score <= 80;
where: 判断选择用
5、查询score表中成绩为85,86或88的记录。
select * from score where score = 50 or score = 80 or score = 87;
6、查询student表中查学Java Web的或性别为“女"的同学记录。
select stu.sno,stu.sname,stu.sbirth,stu.ssex from student stu
left join score sco on stu.sno=sco.sno
left join course cou on cou.cno=sco.cno
where cname = "Java Web" or ssex = "女";
left join:左连接,将两张表以主键字段拼接成一张表
7、以class降序查询student表的所有记录。
select * from student order by sno desc;
order by:排序,默认为升序 desc 为降序
8、以cno升序、score降序查询score表的所有记录。
select * from score ORDER BY cno,score desc;
9、查询学Java Web的学生人数。
select count(stu.sno) from student stu
left join score sco on stu.sno=sco.sno
left join course cou on cou.cno=sco.cno
where cname = 'Java Web' ;
10、查询score表中的最高分的学生学号和课程号。(子查询或者排序)
select sno,cno from score order by score desc limit 1;
limit 3: 取前三个