|
| 1 | +drop database if exists hrs; |
| 2 | +create database hrs default charset utf8; |
| 3 | + |
| 4 | +use hrs; |
| 5 | + |
| 6 | +drop table if exists tb_emp; |
| 7 | +drop table if exists tb_dept; |
| 8 | + |
| 9 | +create table tb_dept |
| 10 | +( |
| 11 | +dno int not null comment '编号', |
| 12 | +dname varchar(10) not null comment '名称', |
| 13 | +dloc varchar(20) not null comment '所在地', |
| 14 | +primary key (dno) |
| 15 | +); |
| 16 | + |
| 17 | +insert into tb_dept values |
| 18 | + (10, '会计部', '北京'), |
| 19 | + (20, '研发部', '成都'), |
| 20 | + (30, '销售部', '重庆'), |
| 21 | + (40, '运维部', '深圳'); |
| 22 | + |
| 23 | +create table tb_emp |
| 24 | +( |
| 25 | +eno int not null comment '员工编号', |
| 26 | +ename varchar(20) not null comment '员工姓名', |
| 27 | +job varchar(20) not null comment '员工职位', |
| 28 | +mgr int comment '主管编号', |
| 29 | +sal int not null comment '员工月薪', |
| 30 | +comm int comment '每月补贴', |
| 31 | +dno int comment '所在部门编号', |
| 32 | +primary key (eno) |
| 33 | +); |
| 34 | + |
| 35 | +alter table tb_emp add constraint fk_emp_mgr foreign key (mgr) references tb_emp (eno); |
| 36 | +alter table tb_emp add constraint fk_emp_dno foreign key (dno) references tb_dept (dno); |
| 37 | + |
| 38 | +insert into tb_emp values |
| 39 | + (7800, '张三丰', '总裁', null, 9000, 1200, 20), |
| 40 | + (2056, '乔峰', '分析师', 7800, 5000, 1500, 20), |
| 41 | + (3088, '李莫愁', '设计师', 2056, 3500, 800, 20), |
| 42 | + (3211, '张无忌', '程序员', 2056, 3200, null, 20), |
| 43 | + (3233, '丘处机', '程序员', 2056, 3400, null, 20), |
| 44 | + (3251, '张翠山', '程序员', 2056, 4000, null, 20), |
| 45 | + (5566, '宋远桥', '会计师', 7800, 4000, 1000, 10), |
| 46 | + (5234, '郭靖', '出纳', 5566, 2000, null, 10), |
| 47 | + (3344, '黄蓉', '销售主管', 7800, 3000, 800, 30), |
| 48 | + (1359, '胡一刀', '销售员', 3344, 1800, 200, 30), |
| 49 | + (4466, '苗人凤', '销售员', 3344, 2500, null, 30), |
| 50 | + (3244, '欧阳锋', '程序员', 3088, 3200, null, 20), |
| 51 | + (3577, '杨过', '会计', 5566, 2200, null, 10), |
| 52 | + (3588, '朱九真', '会计', 5566, 2500, null, 10); |
| 53 | + |
| 54 | + |
| 55 | +-- 查询月薪最高的员工姓名和月薪 |
| 56 | + |
| 57 | +-- 查询员工的姓名和年薪((月薪+补贴)*13) |
| 58 | + |
| 59 | +-- 查询有员工的部门的编号和人数 |
| 60 | + |
| 61 | +-- 查询所有部门的名称和人数 |
| 62 | + |
| 63 | +-- 查询月薪最高的员工(Boss除外)的姓名和月薪 |
| 64 | + |
| 65 | +-- 查询薪水超过平均薪水的员工的姓名和月薪 |
| 66 | + |
| 67 | +-- 查询薪水超过其所在部门平均薪水的员工的姓名、部门编号和月薪 |
| 68 | + |
| 69 | +-- 查询部门中薪水最高的人姓名、月薪和所在部门名称 |
| 70 | + |
| 71 | +-- 查询主管的姓名和职位 |
| 72 | + |
| 73 | +-- 查询月薪排名4~6名的员工姓名和月薪 |
0 commit comments