Skip to content

Commit d3f7728

Browse files
committed
feat: add sql solution to lc problem: No.1972
No.1972.First and Last Call On the Same Day
1 parent 4d38082 commit d3f7728

File tree

3 files changed

+117
-2
lines changed

3 files changed

+117
-2
lines changed

solution/1900-1999/1972.First and Last Call On the Same Day/README.md

+39-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,45 @@ Calls table:
6767
<!-- 这里可写当前语言的特殊实现逻辑 -->
6868

6969
```sql
70-
70+
# Write your MySQL query statement below
71+
with s as (
72+
select
73+
*
74+
from
75+
Calls
76+
union
77+
all
78+
select
79+
recipient_id,
80+
caller_id,
81+
call_time
82+
from
83+
Calls
84+
),
85+
t as (
86+
select
87+
caller_id user_id,
88+
first_value(recipient_id) over(
89+
partition by date_format(call_time, '%Y-%m-%d'),
90+
caller_id
91+
order by
92+
call_time asc
93+
) first,
94+
first_value(recipient_id) over(
95+
partition by date_format(call_time, '%Y-%m-%d'),
96+
caller_id
97+
order by
98+
call_time desc
99+
) last
100+
from
101+
s
102+
)
103+
select
104+
distinct user_id
105+
from
106+
t
107+
where
108+
first = last
71109
```
72110

73111
<!-- tabs:end -->

solution/1900-1999/1972.First and Last Call On the Same Day/README_EN.md

+39-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,45 @@ On 2021-08-11, user 1 and 5 had a call. This call was the only call for both of
6464
### **SQL**
6565

6666
```sql
67-
67+
# Write your MySQL query statement below
68+
with s as (
69+
select
70+
*
71+
from
72+
Calls
73+
union
74+
all
75+
select
76+
recipient_id,
77+
caller_id,
78+
call_time
79+
from
80+
Calls
81+
),
82+
t as (
83+
select
84+
caller_id user_id,
85+
first_value(recipient_id) over(
86+
partition by date_format(call_time, '%Y-%m-%d'),
87+
caller_id
88+
order by
89+
call_time asc
90+
) first,
91+
first_value(recipient_id) over(
92+
partition by date_format(call_time, '%Y-%m-%d'),
93+
caller_id
94+
order by
95+
call_time desc
96+
) last
97+
from
98+
s
99+
)
100+
select
101+
distinct user_id
102+
from
103+
t
104+
where
105+
first = last
68106
```
69107

70108
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Write your MySQL query statement below
2+
with s as (
3+
select
4+
*
5+
from
6+
Calls
7+
union
8+
all
9+
select
10+
recipient_id,
11+
caller_id,
12+
call_time
13+
from
14+
Calls
15+
),
16+
t as (
17+
select
18+
caller_id user_id,
19+
first_value(recipient_id) over(
20+
partition by date_format(call_time, '%Y-%m-%d'),
21+
caller_id
22+
order by
23+
call_time asc
24+
) first,
25+
first_value(recipient_id) over(
26+
partition by date_format(call_time, '%Y-%m-%d'),
27+
caller_id
28+
order by
29+
call_time desc
30+
) last
31+
from
32+
s
33+
)
34+
select
35+
distinct user_id
36+
from
37+
t
38+
where
39+
first = last

0 commit comments

Comments
 (0)