Score
0
Watch 44 Star 256 Fork 69

xuthus / 数据库SQL实战SQLMIT

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
3.查找当前薪水详情以及部门编号dept_no.md 801 Bytes
Copy Edit Web IDE Raw Blame History
xuthus authored 2019-07-31 21:51 . add:1-20

查找当前薪水详情以及部门编号dept_no

题目描述

查找各个部门当前(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,salary,salaries.from_date,salaries.to_date,dept_no from salaries,dept_manager where salaries.emp_no=dept_manager.emp_no and salaries.to_date='9999-01-01' and dept_manager.to_date='9999-01-01'

题解

简单的多表查询

Comment ( 0 )

Sign in for post a comment