LeetCode(数据库)- First and Last Call On the Same Day
Posted 程序员牧码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode(数据库)- First and Last Call On the Same Day相关的知识,希望对你有一定的参考价值。
题目链接:点击打开链接
题目大意:略。
解题思路:注意是‘每天’的第一个和最后一个电话。
AC 代码
with a as (
SELECT caller_id, recipient_id, call_time
FROM Calls
UNION ALL
SELECT recipient_id caller_id, caller_id recipient_id, call_time
FROM Calls
)
SELECT DISTINCT a.caller_id user_id
FROM
(SELECT caller_id, recipient_id, dense_rank() over (PARTITION BY caller_id, DATE_FORMAT(call_time, '%Y-%m-%d') order by call_time) AS rk
FROM a) a
INNER JOIN
(SELECT caller_id, recipient_id, dense_rank() over (PARTITION BY caller_id, DATE_FORMAT(call_time, '%Y-%m-%d') order by call_time DESC) AS rk
FROM a) b
ON a.caller_id = b.caller_id AND a.recipient_id = b.recipient_id AND a.rk = 1 AND b.rk = 1
以上是关于LeetCode(数据库)- First and Last Call On the Same Day的主要内容,如果未能解决你的问题,请参考以下文章
Leetcode 34. Find First and Last Position of Element in Sorted Array
LeetCode 34. Find First and Last Position of Element in Sorted Array
[二分搜索] leetcode 34 Find First and Last Position of Element in Sorted Array
[leetcode][34] Find First and Last Position of Element in Sorted Array
Leetcode 34 Find First and Last Position of Element in Sorted Array 解题思路 (python)
LeetCode找元素Find First and Last Position of Element in Sorted Array