查找各个部门当前(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 s.*, d.dept_no FROM salaries AS s , dept_manager AS d WHERE s.to_date=‘9999-01-01‘ AND d.to_date=‘9999-01-01‘ AND s.emp_no=d.emp_no;
SQL实战——03. 查找各个部门当前(to_date='9999-01-01')领导当前薪水详情以及其对应部门编号dept_no
原文地址:https://www.cnblogs.com/sinodragon21/p/12673956.html
时间: 2024-10-09 23:42:23