0
点赞
收藏
分享

微信扫一扫

数据库练习题

caoxingyu 2022-03-11 阅读 82

第一题

–1、使用sql语句拆线呢出表中所有内容
select * from student;

–2、查询出表中所有score>70的同学的id、name、score
select id,name,score from student where score>70;

–3、更改name字段的数据类型为varchar(50)
alter table student MODIFY COLUMN name varchar(50);

–4、向表中添加一个字段,字段名称为‘pingjia’,字段类型 varchar(20)
ALTER table student add pingjia VARCHAR(20);

–5、更改姓名是张三的同学的分数为88
update student set score=‘88’ where name = ‘张三’;

–6、如果80分为及格线,查询出所有及格的同学的详细信息
select * from student where score > 80;

–7、使用关键字in,查询id值是1或5或7的同学的基本信息
select * from student where id in (1,5,7);

–8、查询id值在5至8的所有同学的基本信息
select * from student where id BETWEEN 5 and 8;

–9、查询姓名是小红并且分数大于60的同学的基本信息
select * from student where name = ‘小红’ and score > 60;

–10、查询姓名是小红或者分数大于90的同学的基本信息
select * from student where name = ‘小红’ or score > 90;


第二题

–1.查询表中所有内容(10分)
select * from emp;

–2.查询表中姓名是张三的所有消息记录(10分)
select * from emp where ename = ‘张三’;

–3.查询表中姓名是三个字组成的所有员工的ename,job,sal字段的对应信息(10分)
select * from emp where ename like ‘___’;

–4.查询表中empno字段从1004至1008所有员工的记录(10分)
select * from emp where empno BETWEEN 1004 and 1008;

–5.查询表中所有job字段是文员并且姓名是黄盖的员工的所有信息(10分)
select * from emp where job = ‘文员’ and ename = ‘黄盖’;

–6.查询表中在2001年以后入职的员工信息(10分)
select * from emp where hiredate>‘2001-01-01’;

select * from emp where date_format(hiredate,’%Y%m%d’)>‘20010101’;

–7.查询表中奖金(COMM)是NULL的员工信息(10分)
select * from emp where comm is null;


第三题

–1.使用sql语句查询出表中id,name,和address字段的所有内容
select id,name,address from student;

–2.使用sql语句查询出表中所有同学的id,name,score
select id,name,score from student;

–3.更改useremail字段的数据类型为varchar(50)
ALTER table student modify column useremail varchar(50);

–4.向表中添加一个字段,字段名称为“pingjia”,字段类型为varchar(20)
alter table student add pingjia varchar(20);

–5.更改姓名是张三的同学的分数为92
update student set score=92 where name = ‘张三’;

–6.如果80分为及格线,查询出所有不及格的同学的详细信息
select * from student where score<80;

–7.把姓名是“小红”的同学的分数在原来的基础上+20
update student set score=score+20 where name = ‘小红’;

–8.使用关键字in,查询id值是1或5或7的同学的基本信息
select * from student where id in(1,5,7);

–9.查询id值在4至9的所有同学的基本信息
select * from student where id between 4 and 9;

–10.查询姓名是小红并且分数大于60的同学的基本信息
select * from student where name = ‘小红’ and score > 60;

–11.查询姓名是小红或者分数大于90的同学的基本信息
select * from student where name = ‘小红’ or score > 90;

–12.查询score字段值是NULL的同学的基本信息
select * from student where score is null;

–13.查询name不是张三的同学的id,name,和score
select id,name,score from student where name <> ‘张三’;
select id,name,score from student where name != ‘张三’;

–14.按地址升序,成绩降序
select * from student order by address asc;
select * from student order by score desc;

–15.对城市进行去重显示
select DISTINCT(address) from student;


第四题

–1.查询表中所有内容
select * from yuangong;

–2.修改表名为”emp”
rename table yuangong to emp222;

–3.修改ename字段的类型为varchar
alter table emp222 MODIFY COLUMN ename VARCHAR(50);

–4.删除表中empno是1014并且ename是黄盖的员工信息
delete from yuangong where empno=‘1014’ and ename = ‘黄盖’;

–5.查询表中empno字段的值是1007,1009或1011员工的所有记录
select * from yuangong where empno in (1007,1009,1011);

–6.查询表中所有job字段是文员并且姓名是张三的员工的所有信息
select * from yuangong where job = ‘文员’ and ename = ‘张三’;

–7.查询表中在2001年以后入职的员工信息
select * from yuangong where hiredate > ‘2001-01-01’;

举报

相关推荐

0 条评论