注意:timestampdiff 三个参数中,第二个比第三个小得到的才是正数
timestampdiff(second,time_stamp,time_end)<=246060
1867. 最大数量高于平均水平的订单
select order_id
from OrdersDetails
group by order_id
having max(quantity) >
all (select avg(quantity) from OrdersDetails group by order_id)
提示:以下是本篇文章正文内容,下面案例可供参考
1875. 将工资相同的雇员分组
select employee_id,name ,salary,
dense_rank()over(order by salary asc)team_id
from(
select *,count(*)over(partition by salary) renci
from Employees)new_table
where renci > 1
order by team_id , employee_id
1934. 确认率
select S.user_id,ifnull(confirmation_rate,0.00) confirmation_rate
from(
select user_id,round(sum(action = 'confirmed')/count(*),2) confirmation_rate
from Confirmations
group by user_id)new_table right join Signups S
on new_table.user_id = S.user_id
1939. 主动请求确认消息的用户
# Write your MySQL query statement below
select user_id
from(
select user_id,time_stamp ,
lead(time_stamp,1)over(partition by user_id order by time_stamp asc) time_end
from Confirmations
order by user_id,time_stamp asc)new_table
#表示的是前一个到后一个需要的秒,所以少前一个比后一个小得到的才是正数
where timestampdiff(second,time_stamp,time_end)<=24*60*60
1972. 同一天的第一个电话和最后一个电话???回头再看
SELECT DISTINCT caller_id AS user_id
FROM (
SELECT *, first_value(recipient_id) OVER w AS first_call, last_value(recipient_id) OVER w AS last_call
FROM (
SELECT caller_id, recipient_id, call_time
FROM calls
UNION ALL
SELECT recipient_id, caller_id, call_time
FROM calls
) c
WINDOW w AS (PARTITION BY caller_id, date_format(call_time, '%Y%m%e') ORDER BY call_time ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
) xx
WHERE first_call = last_call;