mysql 8.0 宋红康 的窗口函数练习题
时间: 2023-08-30 10:03:10 浏览: 130
MySQL 8.0中的窗口函数是SQL查询语言的一种功能,用于在查询结果集中计算和分析数据。宋红康的窗口函数练习题可能包括以下的例子和练习:
1. 计算每个部门的平均工资和最高工资。
示例答案:
SELECT department_id, AVG(salary) OVER (PARTITION BY department_id) AS avg_salary,
MAX(salary) OVER (PARTITION BY department_id) AS max_salary
FROM employees;
2. 计算每个部门的员工数量和该部门的平均工资。
示例答案:
SELECT department_id, COUNT(*) OVER (PARTITION BY department_id) AS employee_count,
AVG(salary) OVER (PARTITION BY department_id) AS avg_salary
FROM employees;
3. 计算每个部门的员工工资排名。
示例答案:
SELECT employee_id, salary, department_id,
DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS salary_rank
FROM employees;
以上仅为示例,宋红康的窗口函数练习题可能包括更多复杂的要求和练习。窗口函数可以用于计算各种分析指标、排序数据并生成报表等,具体问题可能需要根据具体的练习题目进行分析和编写答案。
阅读全文