SQL 习题进阶 二



6

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`));

题目描述

查找所有员工入职时候的薪水情况,给出emp_no以及salary 并按照emp_no进行逆序
selecte.emp_no,s.salary

       from employeese,salaries s

where e.emp_no = s.emp_no and e.hire_date =s.from_date

order by e.emp_no desc;

 

7

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`));

题目描述

查找薪水涨幅超过15次的员工号emp_no以及其对应的涨幅次数t
selectemp_no,count(emp_no) as t 

       from salaries

group by emp_no having t>=15;

 

7、题目描述

找出所有员工当前(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 salary

       fromsalaries

where to_date='9999-01-01'

order by salary desc;

 

8题目描述

获取所有部门当前manager的当前薪水情况,给出dept_no, emp_no以及salary,当前表示to_date='9999-01-01'
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 d.dept_no,d.emp_no,s.salary

       fromsalaries s

join dept_manager d

on s.emp_no = d.emp_no

              andd.to_date = '9999-01-01'

              ands.to_date = '9999-01-01'

 

9

获取所有非manager的员工emp_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 `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 e.emp_no

       fromemployees e

where e.emp_no not in (select emp_no fromdept_manager);

 

10

题目描述

获取所有员工当前的manager,如果当前的manager是自己的话结果不显示,当前表示to_date='9999-01-01'
结果第一列给出当前员工的emp_no,第二列给出其manager对应的manager_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 `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`));

输入描述:

select de.emp_no,dm.emp_no as manager_no

       fromdept_emp de ,dept_manager dm

where de.dept_no = dm.dept_no

and de.emp_no != dm.emp_no

and de.to_date = '9999-01-01'

and dm.to_date = '9999-01-01';

select e.emp_no, m.emp_no as manager_no from dept_empe join dept_manager m

on e.dept_no = m.dept_no

where e.emp_no != m.emp_no

and e.to_date = '9999-01-01'

and m.to_date = '9999-01-01';

你可能感兴趣的:(SQl进阶学习,SQL项目实战,C++项目实战,大数据学习,DBA,oracle)