显示文章标题,发帖人、最后回复时间表:id,title,postuser,postdate,parentid准备sql语句:drop table if exists articles;create table articles(id int auto_increment primary key,title varchar(50),postuser varchar(10),postdate datetime,parentid int references articles(id));insert into articles values(null,'第一条','张三','1998-10-10 12:32:32',null),(null,'第二条','张三','1998-10-10 12:34:32',null),(null,'第一条回复1','李四','1998-10-10 12:35:32',1),(null,'第二条回复1','李四','1998-10-10 12:36:32',2),(null,'第一条回复2','王五','1998-10-10 12:37:32',1),(null,'第一条回复3','李四','1998-10-10 12:38:32',1),(null,'第二条回复2','李四','1998-10-10 12:39:32',2),(null,'第一条回复4','王五','1998-10-10 12:39:40',1);
查看答案
删除除了id号不同,其他都相同的学生冗余信息学生表 如下:id号 学号 姓名 课程编号 课程名称 分数1 2005001 张三 0001 数学 692 2005002 李四 0001 数学 893 2005001 张三 0001 数学 69准备数据:create table student2(id int auto_increment primary key,code varchar(20),name varchar(20));insert into student2 values(null,'2005001','张三'),(null,'2005002','李四'),(null,'2005001','张三');
航空网的几个航班查询题:实验环境:create table city(cityID int auto_increment primary key,cityName varchar(20));create table flight (flightID int auto_increment primary key,StartCityID int references city(cityID),endCityID int references city(cityID),StartTime timestamp);//航班本来应该没有日期部分才好,但是下面的题目当中涉及到了日期insert into city values(null,'北京'),(null,'上海'),(null,'广州');insert into flight values(null,1,2,'9:37:23'),(null,1,3,'9:37:23'),(null,1,2,'10:37:23'),(null,2,3,'10:37:23');(1) 查询起飞城市是北京的所有航班,按到达城市的名字排序(2)查询北京到上海的所有航班纪录(起飞城市,到达城市,起飞时间,航班号)(3)查询具体某一天(2005-5-8)的北京到上海的的航班次数
查出比经理薪水还高的员工信息:准备数据:Drop table if not exists employees;create table employees(id int primary key auto_increment,name varchar(50),salary int,managerid int references employees(id));insert into employees values(null,' lhm',10000,null),(null,' zxx',15000,1),(null,'flx',9000,1),(null,'tg',10000,2),(null,'wzg',10000,3);Wzg大于flx,lhm大于zxx
求出小于45岁的各个老师所带的大于12岁的学生人数实验数据:drop table if exists tea_stu;drop table if exists teacher;drop table if exists student;create table teacher(teaID int primary key,name varchar(50),age int);create table student(stuID int primary key,name varchar(50),age int);create table tea_stu(teaID int references teacher(teaID),stuID int references student(stuID));insert into teacher values (1,'zxx',45), (2,'lhm',25) , (3,'wzg',26) , (4,'tg',27);insert into student values (1,'wy',11), (2,'dh',25) , (3,'ysq',26) , (4,'mxc',27);insert into tea_stu values (1,1), (1,2), (1,3);insert into tea_stu values (2,2), (2,3), (2,4);insert into tea_stu values (3,3), (3,4), (3,1);insert into tea_stu values (4,4), (4,1), (4,2), (4,3);