Java编程

牛客网java练习3,牛客网java练习7

查找最晚入职员工的所有信息 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`));

select * from employeesorder by hire_datedesclimit 0,1;

select * from employeeswhere hire_date=(select max(hire_date) from 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`));

select * from employeesorder by hire_datedesclimit 2,1;

查找各个部门当前(to_date=’9999-01-01′)领导当前薪水详情以及其对应部门编号dept_no 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`)); 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`));

select salaries.emp_no,salaries.salary,salaries.from_date,salaries.to_date,dept_manager.dept_nofrom salaries inner join dept_manageron salaries.emp_no = dept_manager.emp_noand dept_manager.to_date = ‘9999-01-01’and salaries.to_date = ‘9999-01-01’;

查找所有已经分配部门的员工的last_name和first_name 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`)); 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`));

select employees.last_name,employees.first_name,dept_emp.dept_nofrom employees inner join dept_empon employees.emp_no = dept_emp.emp_no查找所有员工的last_name和first_name以及对应部门编号dept_no,也包括展示没有分配具体部门的员工 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`)); 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`));

SELECT ep.last_name, ep.first_name, dp.dept_noFROM employees epLEFT JOIN dept_emp dpON ep.emp_no = dp.emp_no注意: INNER JOIN 两边表同时有对应的数据,即任何一边缺失数据就不显示。 LEFT JOIN 会读取左边数据表的全部数据,即便右边表无对应数据。 RIGHT JOIN 会读取右边数据表的全部数据,即便左边表无对应数据。

查找所有员工入职时候的薪水情况,给出emp_no以及salary, 并按照emp_no进行逆序 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`)); 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`));

select salaries.emp_no,salaries.salaryfrom employees,salarieswhere salaries.emp_no = employees.emp_noand employees.hire_date = salaries.from_dateorder by employees.emp_nodesc

select emp_no,count(emp_no) as tfrom salariesgroup by emp_nohaving t>15找出所有员工当前(to_date=’9999-01-01′)具体的薪水salary情况,对于相同的薪水只显示一次,并按照逆序显示 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`));

select distinct salaryfrom salarieswhere to_date=’9999-01-01’order bysalarydesc

获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date=’9999-01-01′ CREAT

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注