oracle之单行函数之分组函数之课后练习

33. 查询 employees 表中有多少个部门

		select count(distinct department_id)
		from employees		
		
34. 查询全公司奖金基数的平均值(没有奖金的人按 0 计算)

		select avg(nvl(commission_pct, 0))
		from employees		
		
35. 查询各个部门的平均工资

		--错误: avg(salary) 返回公司平均工资, 只有一个值; 而 department_id 有多个值, 无法匹配返回
		select department_id, avg(salary)
		from employees				 
		
		**在 SELECT 列表中所有未包含在组函数中的列都应该包含在 GROUP BY 子句中
		
		--正确: 按 department_id 进行分组
		select department_id, avg(salary)
		from employees
		group by department_id
		
36. Toronto 这个城市的员工的平均工资
		
SELECT avg(salary)
FROM employees e JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON d.location_id = l.location_id
WHERE city = 'Toronto'		

37. (有员工的城市)各个城市的平均工资
	
SELECT city, avg(salary)
FROM employees e JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON d.location_id = l.location_id
GROUP BY city		

38. 查询平均工资高于 8000 的部门 id 和它的平均工资.		

SELECT department_id, avg(salary)
FROM employees e 
GR
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端小歌谣

放弃很容易 但是坚持一定很酷

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值