# Write your MySQL query statement belowSELECT s1.salesperson_id,s1.name,IFNULL(t.total,0) total
FROM Salesperson s1
LEFTJOIN(SELECT c.salesperson_id,SUM(s.price) total
FROM Sales s
INNERJOIN Customer c
ON s.customer_id=c.customer_id
GROUPBY c.salesperson_id
)t
ON s1.salesperson_id=t.salesperson_id
1.3 运行截图
2 将表中的空值更改为前一个值
2.1 题目内容
2.1.1 基本题目信息
2.1.2 示例输入输出
2.2 示例sql语句
# row_number() 显示具体行数WITH T as(SELECT*,row_number()over() rk
FROM CoffeeShop
),
P as(SELECT t2.id,t2.rk b_rk,t1.rk a_rk,(SELECT drink FROM T t3 WHERE t3.rk=MAX(t1.rk)) drink
FROM T t1
INNERJOIN T t2
ON t2.drink isnullAND t1.rk<t2.rk AND t1.drink ISNOTNULLGROUPBY t2.id
)SELECT t4.id,IFNULL(t4.drink,(SELECT p1.drink FROM P p1 WHERE p1.id=t4.id AND p1.b_rk=t4.rk)) drink
FROM T t4
2.3 运行截图
3 开除员工
3.1 题目内容
3.1.1 基本题目信息1
3.1.2 基本题目信息2
3.1.3 示例输入输出
a 示例输入
b 示例输出
3.2 示例sql语句
# 找到没有被开除的,然后去子查询筛选掉,剩下的就是开除的了# 注意:分钟数是向上取整的,先求秒针数,然后除以60,使用ceiling函数向上取整就行SELECT employee_id
FROM Employees
WHERE employee_id NOTIN(SELECT e.employee_id
FROM Employees e
INNERJOIN(SELECT employee_id,SUM(CEILING(TimeStampDiff(SECOND,in_time,out_time)/60)/60) total
FROM Logs
GROUPBY employee_id
)t
ON e.employee_id=t.employee_id AND t.total>=e.needed_hours
)