# Write your MySQL query statement belowWITH t1 as(SELECT order_id,avg(quantity) Aquantity
FROM OrdersDetails
GROUPBY order_id
ORDERBY Aquantity desclimit1)SELECT order_id
FROM OrdersDetails
GROUPBY order_id
HAVINGmax(quantity)>(SELECT Aquantity
FROM t1
)
1.3 运行截图
2 将工资相同的雇员分组
2.1 题目内容
2.1.1 基本题目信息
2.1.2 示例输入输出
2.2 示例sql语句
# 使用dense_rank() 是密集排序 没有dense时会跳过# 窗口函数也可以没有partion by分组这个条件SELECT e1.employee_id,e1.name,e1.salary,dense_rank()over(ORDERBY e1.salary asc) team_id
FROM Employees e1
INNERJOIN(SELECT e.salary
FROM Employees e
GROUPBY e.salary
HAVINGcount(*)>=2)e2
ON e1.salary=e2.salary
ORDERBY team_id asc,employee_id asc
2.3 运行截图
3 按分类统计薪水
3.1 题目内容
3.1.1 基本题目信息
3.1.2 示例输入输出
3.2 示例sql语句
# 需要使用临时表,就使用with 表别名 as (查询到的表)的方式WITH t1 AS(SELECT1 id,'Low Salary' means
UNIONSELECT2 id,'Average Salary' means
UNIONSELECT3 id,'High Salary' means
)SELECT t1.means category,IFNULL(t3.num,0) accounts_count
FROM t1
LEFTJOIN(SELECT t2.id,count(account_id) num
FROM(SELECT account_id,casewhen income<20000then1when income between20000and50000then2else3end id
FROM Accounts
)t2
GROUPBY t2.id
)t3
ON t1.id=t3.id