MySQL基础练习---牛客网的数据以及典型题目
1 部门表departments
部门no和部门名称
2 部门员工表 dept_emp
每个部门对应的员工信息
3 部门经理表 dept_manager
每个部门的经理信息
4 员工表 employees
员工的具体信息
5 薪水表 salaries
所有员工的薪水
6 职称表 titles
所有员工的职称
MySQL代码
- CREATE DATABASE /*!32312 IF NOT EXISTS*/`sqlpractice_nk` /*!40100 DEFAULT CHARACTER SET utf8 */;
- USE `sqlpractice_nk`;
- /*Table structure for table `departments` */
- DROP TABLE IF EXISTS `departments`;
- CREATE TABLE `departments` (
- `dept_no` char(4) NOT NULL,
- `dept_name` varchar(40) NOT NULL,
- PRIMARY KEY (`dept_no`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- /*Data for the table `departments` */
- insert into `departments`(`dept_no`,`dept_name`) values ('d001','Marketing'),('d002','Finance'),('d003','Human Resources'),('d004','Production'),('d005','Development'),('d006','Quality Management');
- /*Table structure for table `dept_emp` */
- DROP TABLE IF EXISTS `dept_emp`;
- CREATE TABLE `dept_emp` (
- `emp_no` int(11) NOT NULL,
- `dept_no` char(4) NOT NULL,
- `from_date` date NOT NULL,
- `to_date` date NOT NULL,
- PRIMARY KEY (`emp_no`,`dept_no`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- /*Data for the table `dept_emp` */
- insert into `dept_emp`(`emp_no`,`dept_no`,`from_date`,`to_date`) values (10001,'d001','1986-06-26','9999-01-01'),(10002,'d001','1996-08-03','9999-01-01'),(10003,'d004','1995-12-03','9999-01-01'),(10004,'d004','1986-12-01','9999-01-01'),(10005,'d003','1989-09-12','9999-01-01'),(10006,'d002','1990-08-05','9999-01-01'),(10007,'d005','1989-02-10','9999-01-01'),(10008,'d005','1998-03-11','2000-07-31'),(10009,'d006','1985-02-18','9999-01-01'),(10010,'d005','1996-11-24','2000-06-26'),(10010,'d006','2000-06-26','9999-01-01');
- /*Table structure for table `dept_manager` */
- DROP TABLE IF EXISTS `dept_manager`;
- CREATE TABLE `dept_manager` (
- `dept_no` char(4) NOT NULL,
- `emp_no` int(11) NOT NULL,
- `from_date` date NOT NULL,
- `to_date` date NOT NULL,
- PRIMARY KEY (`emp_no`,`dept_no`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- /*Data for the table `dept_manager` */
- insert into `dept_manager`(`dept_no`,`emp_no`,`from_date`,`to_date`) values ('d001',10002,'1996-08-03','9999-01-01'),('d004',10004,'1986-12-01','9999-01-01'),('d003',10005,'1989-09-12','9999-01-01'),('d002',10006,'1990-08-05','9999-01-01'),('d005',10010,'1996-11-24','2000-06-26'),('d006',10010,'2000-06-26','9999-01-01');
- /*Table structure for table `employees` */
- DROP TABLE IF EXISTS `employees`;
- CREATE TABLE `employees` (
- `emp_no` int(11) NOT NULL,
- `birth_date` date NOT NULL,
- `first_name` varchar(14) NOT NULL,
- `last_name` varchar(16) NOT NULL,
- `gender` char(1) NOT NULL,
- `hire_date` date NOT NULL,
- PRIMARY KEY (`emp_no`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- /*Data for the table `employees` */
- insert into `employees`(`emp_no`,`birth_date`,`first_name`,`last_name`,`gender`,`hire_date`) values (10001,'1953-09-02','Georgi','Facello','M','1986-06-26'),(10002,'1964-06-02','Bezalel','Simmel','F','1985-11-21'),(10003,'1959-12-03','Parto','Bamford','M','1986-08-28'),(10004,'1954-05-01','Chirstian','Koblick','M','1986-12-01'),(10005,'1955-01-21','Kyoichi','Maliniak','M','1989-09-12'),(10006,'1953-04-20','Anneke','Preusig','F','1989-06-02'),(10007,'1957-05-23','Tzvetan','Zielinski','F','1989-02-10'),(10008,'1958-02-19','Saniya','Kalloufi','M','1994-09-15'),(10009,'1952-04-19','Sumant','Peac','F','1985-02-18'),(10010,'1963-06-01','Duangkaew','Piveteau','F','1989-08-24'),(10011,'1953-11-07','Mary','Sluis','F','1990-01-22');
- /*Table structure for table `salaries` */
- DROP TABLE IF EXISTS `salaries`;
- CREATE TABLE `salaries` (
- `emp_no` int(11) NOT NULL,
- `salary` int(11) NOT NULL,
- `from_date` date NOT NULL,
- `to_date` date NOT NULL,
- PRIMARY KEY (`emp_no`,`from_date`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- /*Data for the table `salaries` */
- insert into `salaries`(`emp_no`,`salary`,`from_date`,`to_date`) values (10001,60117,'1986-06-26','1987-06-26'),(10001,62102,'1987-06-26','1988-06-25'),(10001,66074,'1988-06-25','1989-06-25'),(10001,66596,'1989-06-25','1990-06-25'),(10001,66961,'1990-06-25','1991-06-25'),(10001,71046,'1991-06-25','1992-06-24'),(10001,74333,'1992-06-24','1993-06-24'),(10001,75286,'1993-06-24','1994-06-24'),(10001,75994,'1994-06-24','1995-06-24'),(10001,76884,'1995-06-24','1996-06-23'),(10001,80013,'1996-06-23','1997-06-23'),(10001,81025,'1997-06-23','1998-06-23'),(10001,81097,'1998-06-23','1999-06-23'),(10001,84917,'1999-06-23','2000-06-22'),(10001,85112,'2000-06-22','2001-06-22'),(10001,85097,'2001-06-22','2002-06-22'),(10001,88958,'2002-06-22','9999-01-01'),(10002,72527,'1996-08-03','1997-08-03'),(10002,72527,'1997-08-03','1998-08-03'),(10002,72527,'1998-08-03','1999-08-03'),(10002,72527,'1999-08-03','2000-08-02'),(10002,72527,'2000-08-02','2001-08-02'),(10002,72527,'2001-08-02','9999-01-01'),(10003,40006,'1995-12-03','1996-12-02'),(10003,43616,'1996-12-02','1997-12-02'),(10003,43466,'1997-12-02','1998-12-02'),(10003,43636,'1998-12-02','1999-12-02'),(10003,43478,'1999-12-02','2000-12-01'),(10003,43699,'2000-12-01','2001-12-01'),(10003,43311,'2001-12-01','9999-01-01'),(10004,40054,'1986-12-01','1987-12-01'),(10004,42283,'1987-12-01','1988-11-30'),(10004,42542,'1988-11-30','1989-11-30'),(10004,46065,'1989-11-30','1990-11-30'),(10004,48271,'1990-11-30','1991-11-30'),(10004,50594,'1991-11-30','1992-11-29'),(10004,52119,'1992-11-29','1993-11-29'),(10004,58326,'1994-11-29','1995-11-29'),(10004,60770,'1995-11-29','1996-11-28'),(10004,62566,'1996-11-28','1997-11-28'),(10004,64340,'1997-11-28','1998-11-28'),(10004,67096,'1998-11-28','1999-11-28'),(10004,69722,'1999-11-28','2000-11-27'),(10004,70698,'2000-11-27','2001-11-27'),(10004,74057,'2001-11-27','9999-01-01'),(10005,78228,'1989-09-12','1990-09-12'),(10005,82621,'1990-09-12','1991-09-12'),(10005,83735,'1991-09-12','1992-09-11'),(10005,85572,'1992-09-11','1993-09-11'),(10005,85076,'1993-09-11','1994-09-11'),(10005,86050,'1994-09-11','1995-09-11'),(10005,88448,'1995-09-11','1996-09-10'),(10005,89724,'1997-09-10','1998-09-10'),(10005,90392,'1998-09-10','1999-09-10'),(10005,90531,'1999-09-10','2000-09-09'),(10005,91453,'2000-09-09','2001-09-09'),(10005,94692,'2001-09-09','9999-01-01'),(10006,43311,'1990-08-05','1991-08-05'),(10006,43311,'1991-08-05','1992-08-04'),(10006,43311,'1992-08-04','1993-08-04'),(10006,43311,'1993-08-04','1994-08-04'),(10006,43311,'1994-08-04','1995-08-04'),(10006,43311,'1995-08-04','1996-08-03'),(10006,43311,'1996-08-03','1997-08-03'),(10006,43311,'1997-08-03','1998-08-03'),(10006,43311,'1998-08-03','1999-08-03'),(10006,43311,'1999-08-03','2000-08-02'),(10006,43311,'2000-08-02','2001-08-02'),(10006,43311,'2001-08-02','9999-01-01'),(10007,56724,'1989-02-10','1990-02-10'),(10007,60740,'1990-02-10','1991-02-10'),(10007,62745,'1991-02-10','1992-02-10'),(10007,63475,'1992-02-10','1993-02-09'),(10007,63208,'1993-02-09','1994-02-09'),(10007,64563,'1994-02-09','1995-02-09'),(10007,68833,'1995-02-09','1996-02-09'),(10007,70220,'1996-02-09','1997-02-08'),(10007,73362,'1997-02-08','1998-02-08'),(10007,75582,'1998-02-08','1999-02-08'),(10007,79513,'1999-02-08','2000-02-08'),(10007,80083,'2000-02-08','2001-02-07'),(10007,84456,'2001-02-07','2002-02-07'),(10007,88070,'2002-02-07','9999-01-01'),(10008,46671,'1998-03-11','1999-03-11'),(10008,48584,'1999-03-11','2000-03-10'),(10008,52668,'2000-03-10','2000-07-31'),(10009,60929,'1985-02-18','1986-02-18'),(10009,64604,'1986-02-18','1987-02-18'),(10009,64780,'1987-02-18','1988-02-18'),(10009,66302,'1988-02-18','1989-02-17'),(10009,69042,'1989-02-17','1990-02-17'),(10009,70889,'1990-02-17','1991-02-17'),(10009,71434,'1991-02-17','1992-02-17'),(10009,74612,'1992-02-17','1993-02-16'),(10009,76518,'1993-02-16','1994-02-16'),(10009,78335,'1994-02-16','1995-02-16'),(10009,80944,'1995-02-16','1996-02-16');
- /*Table structure for table `titles` */
- DROP TABLE IF EXISTS `titles`;
- CREATE TABLE `titles` (
- `emp_no` int(11) NOT NULL,
- `title` varchar(50) NOT NULL,
- `from_date` date NOT NULL,
- `to_date` date NOT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- /*Data for the table `titles` */
- insert into `titles`(`emp_no`,`title`,`from_date`,`to_date`) values (10001,'Senior Engineer','1986-06-26','9999-01-01'),(10002,'Staff','1996-08-03','9999-01-01'),(10003,'Senior Engineer','1995-12-03','9999-01-01'),(10004,'Engineer','1986-12-01','1995-12-01'),(10004,'Senior Engineer','1995-12-01','9999-01-01'),(10005,'Senior Staff','1996-09-12','9999-01-01'),(10005,'Staff','1989-09-12','1996-09-12'),(10006,'Senior Engineer','1990-08-05','9999-01-01'),(10007,'Senior Staff','1996-02-11','9999-01-01'),(10007,'Staff','1989-02-10','1996-02-11'),(10008,'Assistant Engineer','1998-03-11','2000-07-31'),(10009,'Assistant Engineer','1985-02-18','1990-02-18'),(10009,'Engineer','1990-02-18','1995-02-18'),(10009,'Senior Engineer','1995-02-18','9999-01-01'),(10010,'Engineer','1996-11-24','9999-01-01'),(10010,'Engineer','1996-11-24','9999-01-01');
典型题目汇总
以下题目是在第二遍做时遇到困难的:
(1)从titles表获取按照title进行分组,注意对于重复的title进行忽略
(2)查找所有员工自入职以来的薪水涨幅情况
(3)对所有员工的薪水按照salary进行按照1-N的排名
(4)获取员工其当前的薪水比其manager当前薪水还高的相关信息
(5)汇总各个部门当前员工的title类型的分配数目
(6)
0
MySQL基础练习---牛客网的数据以及典型题目的更多相关文章
- 牛客网国庆集训派对Day5 题目 2018年
链接:https://www.nowcoder.com/acm/contest/205/L来源:牛客网参考博客:https://blog.csdn.net/HTallperson/article/de ...
- 牛客网国庆集训派对Day4题目 2018年
链接:https://www.nowcoder.com/acm/contest/204/A来源:牛客网 深度学习 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他 ...
- 牛客网国庆集训派对Day3题目 2018年
链接:https://www.nowcoder.com/acm/contest/203/D来源:牛客网 Shopping 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K ...
- 牛客网国庆集训派对Day6 题目 2018年
链接:https://www.nowcoder.com/acm/contest/206/A来源:牛客网 Birthday 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576 ...
- MySQL基础练习02---牛客网
目录 1. 从titles表中获取title并按照title分组 2.从titles表中获取title并按照title分组,重复的emp_no忽略 3 查找employees表 4 统计平均工资 5 ...
- MySQL基础练习01--牛客网
目录 1 查找最晚入职员工的信息 2 查找入职第三晚的员工信息 3 查找当前薪水详情及部门编号 4 查找所有员工入职时的薪水情况 5 查找已分配员工姓名 6 查找员工姓名 7 查找涨薪找过15次的员工 ...
- 加法运算替代 牛客网 程序员面试金典 C++ Python
加法运算替代 牛客网 程序员面试金典 题目描述 请编写一个方法,实现整数的乘法.减法和除法运算(这里的除指整除).只允许使用加号. 给定两个正整数int a,int b,同时给定一个int type代 ...
- 算法题16 贪吃的小Q 牛客网 腾讯笔试题
算法题16 贪吃的小Q 牛客网 腾讯笔试题 题目: 链接:https://www.nowcoder.com/questionTerminal/d732267e73ce4918b61d9e3d0ddd9 ...
- 像素反转 牛客网 程序员面试金典 C++ Python
像素反转 牛客网 程序员面试金典 题目描述 有一副由NxN矩阵表示的图像,这里每个像素用一个int表示,请编写一个算法,在不占用额外内存空间的情况下(即不使用缓存矩阵),将图像顺时针旋转90度. 给定 ...
随机推荐
- java CGLib代理
转载自 cglib之Enhancer 1. 背景 cglib库的Enhancer在Spring AOP中作为一种生成代理的方式被广泛使用.本文针对Enhancer的用法以实际代码为例作一些介绍. ...
- java中讲讲PrintStream的用法,举例?
[学习笔记] 1.2 PrintStream的用法 从学java第一天,我们就经常用到System.out.println(),实际上查阅文档可知,System.out就是Sun 编的一个Prin ...
- flink两种安装方式
Flink Standalone 集群 HA 配置 1. HA 集群环境规划 使用三台节点实现两主两从集群(由于笔记本性能限制,不能开启太多虚拟机,其实使用三 台和四台机器在安装配置上没有本质区别) ...
- springboot中配置文件使用1
1.表达方式:application.properties或者application.yml,这是已经约定成俗的文件,不用修改文件名,此文件为全局配置文件. 2.语法格式:yml或者yaml. a.基 ...
- 第六章 ZYNQ-MIZ701 GPIO使用之MIO
6.0 本章难度系数★★☆☆☆☆☆ 6.1 GPIO简介 Zynq7000系列芯片有54个MIO(multiuse I/O),它们分配在 GPIO 的Bank0 和Bank1隶属于PS部分,这些I ...
- gulp做简单的js压缩
安装工具 全局安装npm install --global gulp 项目的依赖安装npm install --save-dev gulp npm install --save-dev gulp-re ...
- 如何演讲-摘录自TED
一.首先,只传递一个主要思想 想法是个很复杂的东西,你要对你的内容做减法,突出重点,只关注一个主要思想,也就是你最富有热情的观点,利用机会好好的阐述它.你要给出案例,分享案例,生动阐述所以,找到一个 ...
- [转载]PyTorch中permute的用法
[转载]PyTorch中permute的用法 来源:https://blog.csdn.net/york1996/article/details/81876886 permute(dims) 将ten ...
- requests模块发送数据
通过json dumps发送 import requests import json def agent(): """ 执行命令采集硬件信息 将执行的信息发送给API : ...
- Mac下安装Redis及Redis Desktop Manager
1.简介 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 它支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表 ...