数据库相关习题

数据库相关习题

create table student(
	id int,
	name varchar(20),
	chinese float,
	english float,
	math float
);

在这里插入图片描述

  1. 请添加2列信息,出生日期,籍贯。
alter table student add birthday varchar(50);
alter table student modify birthday date;
alter table student add address varchar(50);
select * from student;

在这里插入图片描述

3,请修改语文成绩的数据类型为int型.

alter table student modify chinese  int;
desc student;

在这里插入图片描述

  1. 请将各科成绩修改为默认值为0
alter table student alter column chinese set default 0;
alter table student alter column english set default 0;
alter table student alter column math set default 0;
desc student;

在这里插入图片描述

  1. 请在里面插入10名学生数据。(名字请以汉字输入)
alter database mysql character set utf8 collate utf8_bin;
-- 否则 Incorrect string value: '\xE9\xAB\x98\xE6\xBA\x90' for column 'name' at row 1
show create database mysql;
insert into student (id,name,chinese,english,math,birthday,address) value (1,'高源',100,100,99,'1996-09-06','成都');
insert into student (id,name,chinese,english,math,birthday,address) value (2,'张旭辉',99,100,99,'1999-09-06','苏州');

insert into student (id,name,chinese,english,math,birthday,address) value (3,'汪光武',99,98,99,'1999-09-06','安徽');

insert into student (id,name,chinese,english,math,birthday,address) value (4,'叶强',78,90,89,'1995-09-06','河南');

insert into student (id,name,chinese,english,math,birthday,address) value (5,'颜洪斌',87,90,77,'1995-09-06','湖南');

insert into student (id,name,chinese,english,math,birthday,address) value (6,'李臣',100,88,56,'1994-09-06','中国');
insert into student (id,name,chinese,english,math,birthday,address) value (7,'代志成',89,100,99,'1993-09-06','中国');

insert into student (id,name,chinese,english,math,birthday,address) value (8,'孔佑贤',100,89,97,'1993-09-06','中国');

insert into student (id,name,chinese,english,math,birthday,address) value (9,'林可翰',78,100,95,'1992-09-06','成都');

insert into student (id,name,chinese,english,math,birthday,address) value (10,'王雪茄',100,79,99,'1991-09-06','王道');

insert into student (id,name,chinese,english,math,birthday,address) value (11,'正派雪茄',59,59,59,'1991-09-06','王道');
-- delete from  student where id =1;
select * from student;

在这里插入图片描述

  1. 请分别找出单科成绩最高的学生名单。语文最高的,英语最高的,数学最高的。
select name,math as max_math from student where math = (select max(math) from student);

select name,english as max_english from student where english = (select max(english) from student);

select name,chinese as max_chinese from student where chinese = (select max(chinese) from student);

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

  1. 请找出总成绩最高的学生。
select name,(chinese+math+english)  as max_num from student where(chinese+math+english) = (select max(chinese+math+english) from student);

在这里插入图片描述

10.假设10名同学中有同姓的,如王,请找出姓王同学的信息.

select * from student where name like '王%';


在这里插入图片描述

11.请找出各科不及格学生的信息。

select * from student where math<60 and english<60 and chinese<60;

在这里插入图片描述

12.请找出有任何一科不及格学生的名称


select * from student where math<60 or english<60 or chinese<60;

在这里插入图片描述

13.请找出两科成绩在90分以上的学生名称。

select * from student where (math>90 and english>90) or (math>90 and chinese>90 ) or (english>90 and chinese>90 );

在这里插入图片描述

14.请找出没有一科挂科的学生名称。

select * from student where math>60 and english>60 and chinese>60;

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/gy99csdn/article/details/114495101