数据库题目

2017-12-21  本文已影响0人  背起我的破书包

1.数据库中有如下两个表:

表1:employee

员工编号:employee_id (NOT allows null)

员工姓名:employee_name (NOT allows null)

年 龄 :age,

雇用日期:hire_date,

部门:department

表2:salary

员工编号:employee_id

员工工资:salary

关于日期函数:

year(date)返回日期中的年份;

month(date)返回日期中的月份;

day(date)返回日期中的天;

(1)计算2015年以后雇佣的员工个数

select count(*) from employee where year(hire_date)>2015;

(2)工资大于9000的员工编号、姓名和工资

select employee.employee_id,employee.employee_name,salary.salary from employy,salary where salary>900 and employee.employee_id=salart.employee_id;

(3)计算各个部门的员工个数,表头显示为:部门、员工个数

select department as 部门,count(*) as 员工个数 from employee group by department;

(4)按工资的高低列出工资表

select * from salary order by salary;

(5)个人操作中用到的一些sql语句

select * from salary order by salary desc;

删除表中的一个字段:

alter table salary drop column employee_id;

新增字段salary:

alter table salary  add employee_id

2.数据库查询 对下面两张表进行查询操作:

学生信息表student:

班级信息表class:

(1)目前要查询班主任LiFang的班级下全体学生的信息情况。 要求:用两种不同的sql查询语句(连接查询和嵌套查询),并说明两种sql语句的执行效率哪个更高以及原因。

a.连接查询

select * from student  inner join class on calss.class_id =student.calss_id where class.Master="Li Fang";

b.嵌套查询

select * from student calss_id in(select calss_id from class where Matser="Li Fang");

3)操作中遇到的一些问题

插入数据的时候报了下面的错误:

该错误是由于输入了中文,Class_ID 的属性为char(255),不能接收中文,修改字段的属性为下面即可:\

alter table student modify Class_ID char(255) charset uft8;

修改某个字段的内容(把Li XiaoTing的Student_ID号改为2)

update student set Student_ID=2 where Student_Name="Li Xiao Ting";

上一篇 下一篇

猜你喜欢

热点阅读