SQL16 - 统计出当前各个title类型对应的员工当前薪水对应的平均工资
题目描述:
统计出当前(titles.to_date='9999-01-01')各个title类型对应的员工当前(salaries.to_date='9999-01-01')薪水对应的平均工资。结果给出title以及平均工资avg。
1 CREATE TABLE `salaries` ( 2 `emp_no` int(11) NOT NULL, 3 `salary` int(11) NOT NULL, 4 `from_date` date NOT NULL, 5 `to_date` date NOT NULL, 6 PRIMARY KEY (`emp_no`,`from_date`)); 7 8 CREATE TABLE IF NOT EXISTS "titles" ( 9 `emp_no` int(11) NOT NULL, 10 `title` varchar(50) NOT NULL, 11 `from_date` date NOT NULL, 12 `to_date` date DEFAULT NULL);
难易程度:
中等
解答:
1 select titles.title,avg(salaries.salary) 2 from titles 3 left join salaries 4 on titles.emp_no = salaries.emp_no 5 where titles.to_date='9999-01-01' 6 and salaries.to_date='9999-01-01' 7 group by titles.title

浙公网安备 33010602011771号