当前位置: 移动技术网 > IT编程>数据库>MSSQL > 数据库SQL实战题:获取员工其当前的薪水比其manager当前薪水还高的相关信息(教程)

数据库SQL实战题:获取员工其当前的薪水比其manager当前薪水还高的相关信息(教程)

2018年11月03日  | 移动技术网IT编程  | 我要评论

有些h的长筒袜事典,南京在线 025002,斯坦·海尔辛

获取员工其当前的薪水比其manager当前薪水还高的相关信息,当前表示to_date=’9999-01-01’,

结果第一列给出员工的emp_no,

第二列给出其manager的manager_no,

第三列给出该员工当前的薪水emp_salary,

第四列给该员工对应的manager当前的薪水manager_salary

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

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

这类直接暴力使用where,注意题目的条件。

select e.emp_no as emp_no,m.emp_no as manager_no,s1.salary as emp_salary,s2.salary as manager_salary
from salaries s1,salaries s2,dept_emp e,dept_manager m
where e.emp_no=s1.emp_no
and m.emp_no=s2.emp_no
and e.dept_no=m.dept_no
and e.emp_no!=m.emp_no
and s1.salary>s2.salary
and e.to_date='9999-01-01'
and m.to_date='9999-01-01'
and s1.to_date='9999-01-01'
and s2.to_date='9999-01-01'

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网