用户登录
用户注册

分享至

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

  • 作者: 熙沫女神
  • 来源: 51数据库
  • 2021-09-05

获取员工其当前的薪水比其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'
软件
前端设计
程序设计
Java相关