sql 语句的一些练习
-
create table Student(
-
no int,
-
name varchar(20),
-
sex varchar(20),
-
birthday varchar(30),
-
class varchar(20));
-
create table Teacher(
-
no int,
-
name varchar(20),
-
sex varchar(20),
-
birthday varchar(30),
-
prof varchar(20),
-
depart varchar(20);
-
create table Course(
-
cno varchar(20),
-
cname varchar(20),
-
tno int
-
);
-
create table Score(
-
no int,
-
cno varchar(20),
-
degree int
-
);
insert into Course values('3-101','数据库',1)
insert into Course values('5-102','数学',3)
insert into Course values('3-103','信息系统',4)
insert into Course values('3-104','操作系统',6)
insert into Course values('3-105','数据结构',4)
insert into Course values('3-106','数据处理',5)
insert into Course values('4-107','pascal语言',5)
insert into Course values('4-108','c++',7)
insert into Course values('4-109','java',8)
insert into Course values('3-245','数据挖掘',10)
insert into Course values('3-111','软件工程',11)
insert into Score values(5001,'3-105',69)
insert into Score values(5001,'5-102',55)
insert into Score values(5003,'4-108',85)
insert into Score values(5004,'3-105',77)
insert into Score values(5005,'3-245',100)
insert into Score values(5006,'3-105',53)
insert into Score values(5003,'4-109',45)
insert into Score values(5008,'3-105',98)
insert into Score values(5004,'4-109',68)
insert into Score values(5010,'3-105',88)
insert into Score values(5003,'3-105',98)
insert into Score values(5005,'4-109',68)
insert into Score values(5002,'3-105',88)
insert into Score values(107,'3-105',98)
insert into Score values(108,'4-109',68)
insert into Score values(109,'3-105',88)
insert into Score values(107,'3-111',88)
insert into Score values(5003,'3-111',80)
insert into Student values(5001,'李勇','男','1987-7-22',95001)
insert into Student values(5002,'刘晨','女','1987-11-1',95002)
insert into Student values(5003,'王敏','女','1987-10-5',95001)
insert into Student values(5004,'李好尚','男','1987-9-25',95003)
insert into Student values(5005,'李军','男','1987-7-17',95004)
insert into Student values(5006,'范新位','女','1987-6-18',95005)
insert into Student values(5007,'张霞东','女','1987-8-29',95006)
insert into Student values(5008,'赵薇','男','1987-6-15',95007)
insert into Student values(5009,'钱民将','女','1987-6-23',95008)
insert into Student values(5010,'孙俪','女','1987-9-24',95002)
insert into Student values(108,'赵里','男','1987-6-15',95007)
insert into Student values(109,'丘处机','男','1987-6-23',95008)
insert into Student values(107,'杨康','男','1987-9-24',95001)
insert into Teacher values(1,'李卫','男','1957-11-5','教授','电子工程系')
insert into Teacher values(2,'刘备','男','1967-10-9','副教授','math')
insert into Teacher values(3,'关羽','男','1977-9-20','讲师','sc')
insert into Teacher values(4,'李修','男','1957-6-25','教授','elec')
insert into Teacher values(5,'诸葛亮','男','1977-6-15','教授','计算机系')
insert into Teacher values(6,'殷素素','女','1967-1-5','副教授','sc')
insert into Teacher values(7,'周芷若','女','1947-2-23','教授','sc')
insert into Teacher values(8,'赵云','男','1980-6-13','副教授','计算机系')
insert into Teacher values(9,'张敏','女','1985-5-5','助教','sc')
insert into Teacher values(10,'黄蓉','女','1967-3-22','副教授','sc')
insert into Teacher values(11,'张三','男','1967-3-22','副教授','sc')
3.select * from student order by class desc;
4.select depart from teacher group by depart;
5.select name,sex,class from student;
6.select name from student where name not like '王%';
7. select no,cno,degree from score where degree=85 or degree=86 or degree=88 or degree between 60 and 80;
8. select no,name,sex,birthday,class from student where class='95001'or sex='女';
9.select no,cno,degree from score order by cno asc,degree desc;
10.selcet count(sex),count(class) from student where sex='男';
11. select cno from score where degree>85 group by cno;
12.select count(*) from student where class=95001;
13.select avg(degree) from score where cno='3-105';
14. select max(birthday),min(birthday) from student;
15.select * from student where class=95001 or class=95004;
16. select cno,avg(degree),max(degree),min(degree) from score where cno like '3%' group by cno having count(*)>=5;