数据库sql查询语句练习
1.上述表的建表语句
2.给出相应的INSRET语句完成题中给出数据的插入
3.以class降序输出student的所有记录(student表全部属性)
命令:select * from student order by class desc;
4.列出教师所在的单位depart(不重复)。
命令: select distinct depart from teacher;
5.列出student表中所有记录的name、sex和class列
命令: select name,sex,class from student;
6.输出student中不姓王的同学的姓名。
命令:select name from Student where name not like ' 王 %' ;
7.输出成绩为85或86或88或在60-80之间的记录(no,cno,degree)
命令: select * from score where degree in(85,86,88);
8.输出班级为95001或性别为‘女’ 的同学(student表全部属性)
命令:select * from student WHERE class = '95001' OR sex = '女';
9.以cno升序、degree降序输出score的所有记录。(score表全部属性)
命令: select * from score ORDER BY cno ASC,degree DESC;
10.输出男生人数及这些男生分布在多少个班级中
命令: select COUNT (*), count ( distinct class ) from Student where sex = ' 男 ' ;
11.列出存在有85分以上成绩的课程编号。
命令: select distinct cno from Score where degree > 85 ;
12.输出95001班级的学生人数
命令: select count(no) from student WHERE class ='95001';
13.输出‘3-105’号课程的平均分
命令: select avg(degree) from score where cno='3-105';
14.输出student中最大和最小的birthday日期值
命令: select max(birthday),min(birthday)from student;
15.显示95001和95004班全体学生的全部个人信息(不包括选课)。(student表全部属性)
命令:select * from student where class in('95001','95004') order by class;