61 Star 425 Fork 144

xuthus / 数据库SQL实战

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
3.查找当前薪水详情以及部门编号dept_no.md 801 Bytes
一键复制 编辑 原始数据 按行查看 历史
xuthus 提交于 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'

题解

简单的多表查询

SQL
1
https://gitee.com/xuthus5/Database-SQL-Actual-Combat.git
git@gitee.com:xuthus5/Database-SQL-Actual-Combat.git
xuthus5
Database-SQL-Actual-Combat
数据库SQL实战
master

搜索帮助