CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Day36-45/code/HRS_create_and_init.sql
Views: 729
-- 创建名为hrs的数据库1drop database if exists `hrs`;2create database `hrs` default charset utf8mb4;34-- 切换到hrs数据库5use `hrs`;67-- 创建部门表8create table `tb_dept`9(10`dno` int not null comment '编号',11`dname` varchar(10) not null comment '名称',12`dloc` varchar(20) not null comment '所在地',13primary key (dno)14);1516-- 插入4个部门17insert into `tb_dept` values18(10, '会计部', '北京'),19(20, '研发部', '成都'),20(30, '销售部', '重庆'),21(40, '运维部', '深圳');2223-- 创建员工表24create table `tb_emp`25(26`eno` int not null comment '员工编号',27`ename` varchar(20) not null comment '员工姓名',28`job` varchar(20) not null comment '员工职位',29`mgr` int comment '主管编号',30`sal` int not null comment '员工月薪',31`comm` int comment '每月补贴',32`dno` int comment '所在部门编号',33primary key (eno),34constraint `fk_emp_mgr` foreign key (`mgr`) references tb_emp (`eno`),35constraint `fk_emp_dno` foreign key (`dno`) references tb_dept (`dno`)36);3738-- 插入14个员工39insert into `tb_emp` values40(7800, '张三丰', '总裁', null, 9000, 1200, 20),41(2056, '乔峰', '分析师', 7800, 5000, 1500, 20),42(3088, '李莫愁', '设计师', 2056, 3500, 800, 20),43(3211, '张无忌', '程序员', 2056, 3200, null, 20),44(3233, '丘处机', '程序员', 2056, 3400, null, 20),45(3251, '张翠山', '程序员', 2056, 4000, null, 20),46(5566, '宋远桥', '会计师', 7800, 4000, 1000, 10),47(5234, '郭靖', '出纳', 5566, 2000, null, 10),48(3344, '黄蓉', '销售主管', 7800, 3000, 800, 30),49(1359, '胡一刀', '销售员', 3344, 1800, 200, 30),50(4466, '苗人凤', '销售员', 3344, 2500, null, 30),51(3244, '欧阳锋', '程序员', 3088, 3200, null, 20),52(3577, '杨过', '会计', 5566, 2200, null, 10),53(3588, '朱九真', '会计', 5566, 2500, null, 10);545556-- 查询月薪最高的员工姓名和月薪5758-- 查询员工的姓名和年薪(年薪=(sal+comm)*13)5960-- 查询有员工的部门的编号和人数6162-- 查询所有部门的名称和人数6364-- 查询月薪超过平均月薪的员工的姓名和月薪6566-- 查询月薪超过其所在部门平均月薪的员工的姓名、部门编号和月薪6768-- 查询部门中月薪最高的人姓名、月薪和所在部门名称6970-- 查询主管的姓名和职位7172-- 查询月薪排名4~6名的员工排名、姓名和月薪7374-- 查询每个部门月薪排前2名的员工姓名、月薪和部门编号757677