获取所有非manager员工当前的薪水情况

sql实战 获取所有非manager员工当前的薪水情况

  • 问题描述
  • Sql语句

问题描述

获取所有非manager员工当前的薪水情况,给出dept_no、emp_no以及salary ,当前表示to_date=‘9999-01-01’
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 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));

来源:牛客网
链接:https://www.nowcoder.com/practice/8fe212a6c71b42de9c15c56ce354bebe?tpId=82&&tqId=29776&rp=1&ru=/ta/sql&qru=/ta/sql/question-ranking

Sql语句

思路:三个表链接

select dept_emp.dept_no, employees.emp_no, salaries.salary 
from employees, dept_emp, salaries
where employees.emp_no = dept_emp.emp_no
and dept_emp.emp_no = salaries.emp_no
and employees.emp_no not in(select emp_no
                           from dept_manager)
and salaries.to_date='9999-01-01'

你可能感兴趣的:(SQL实战)