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
16.统计出当前各个title类型对应的员工当前薪水对应的平均工资.md 799 Bytes
Copy Edit Web IDE Raw Blame History
xuthus authored 2019-08-13 08:38 . revise:content revision

统计出当前各个title类型对应的员工当前薪水对应的平均工资

题目描述

统计出当前各个title类型对应的员工当前(to_date='9999-01-01')薪水对应的平均工资。结果给出title以及平均工资avg。

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`));
CREATE TABLE IF NOT EXISTS "titles" (
`emp_no` int(11) NOT NULL,
`title` varchar(50) NOT NULL,
`from_date` date NOT NULL,
`to_date` date DEFAULT NULL);

答案

select title,avg(salary) avg from titles t left join salaries s on t.emp_no = s.emp_no where t.to_date = '9999-01-01' and  s.to_date = '9999-01-01' group by title

题解

分组聚合

Comment ( 0 )

Sign in for post a comment