用一条SQL语句查询出每门课都大于80分的学生姓名准备数据的sql代码:create table score(id int primary key auto_increment, name varchar(20),sub ject varchar(20), score int);insert into score values (null,'张三','语文',81), (null,'张三','数学',75), (null,'李四','语文',76), (null,'李四','数学',90),(null,'王 五','语文',81), (null,'王五','数学',100), (null,'王五 ','英语',90);
每个月份的发生额都比101科目多的科目请用SQL语句实现:从TestDB数据表中查询出所有月份的发生额都比101科目相应月份的发生额高的科目。请注意:TestDB中有很多科目,都有1-12月份的发生额。 AccID:科目代码,Occmonth:发生额月份,DebitOccur:发生额。 数据库名:JcyAudit,数据集:Select * from TestDB准备数据的sql代码:drop table if exists TestDB;create table TestDB(id int primary key auto_increment,AccID varchar(20),Occmonth date,DebitOccur bigint);insert into TestDB values(null,'101','1988-1-1',100),(null,'101','1988-2-1',110),(null,'101','1988-3-1',120),(null,'101','1988-4-1',100),(null,'101','1988-5-1',100),(null,'101','1988-6-1',100),(null,'101','1988-7-1',100),(null,'101','1988-8-1',100);--复制上面的数据,故意把第一个月份的发生额数字改小一点insert into TestDB values(null,'102','1988-1-1',90),(null,'102','1988-2-1',110),(null,'102','1988-3-1',120),(null,'102','1988-4-1',100),(null,'102','1988-5-1',100),(null,'102','1988-6-1',100),(null,'102','1988-7-1',100),(null,'102','1988-8-1',100);--复制最上面的数据,故意把所有发生额数字改大一点insert into TestDB values(null,'103','1988-1-1',150),(null,'103','1988-2-1',160),(null,'103','1988-3-1',180),(null,'103','1988-4-1',120),(null,'103','1988-5-1',120),(null,'103','1988-6-1',120),(null,'103','1988-7-1',120),(null,'103','1988-8-1',120);--复制最上面的数据,故意把所有发生额数字改大一点insert into TestDB values(null,'104','1988-1-1',130),(null,'104','1988-2-1',130),(null,'104','1988-3-1',140),(null,'104','1988-4-1',150),(null,'104','1988-5-1',160),(null,'104','1988-6-1',170),(null,'104','1988-7-1',180),(null,'104','1988-8-1',140);--复制最上面的数据,故意把第二个月份的发生额数字改小一点insert into TestDB values(null,'105','1988-1-1',100),(null,'105','1988-2-1',80),(null,'105','1988-3-1',120),(null,'105','1988-4-1',100),(null,'105','1988-5-1',100),(null,'105','1988-6-1',100),(null,'105','1988-7-1',100),(null,'105','1988-8-1',100);
统计每年每月的信息year month amount1991 1 1.11991 2 1.21991 3 1.31991 4 1.41992 1 2.11992 2 2.21992 3 2.31992 4 2.4查成这样一个结果:year m1 m2 m3 m41991 1.1 1.2 1.3 1.41992 2.1 2.2 2.3 2.4准备sql语句:drop table if exists sales;create table sales(id int auto_increment primary key,year varchar(10),month varchar(10),amount float(2,1));insert into sales values(null,'1991','1',1.1),(null,'1991','2',1.2),(null,'1991','3',1.3),(null,'1991','4',1.4),(null,'1992','1',2.1),(null,'1992','2',2.2),(null,'1992','3',2.3),(null,'1992','4',2.4);
显示文章标题,发帖人、最后回复时间表: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);