# 1972. First and Last Call On the Same Day

<https://leetcode.com/problems/first-and-last-call-on-the-same-day>

## Description

Table: `Calls`

```
+--------------+----------+
| Column Name  | Type     |
+--------------+----------+
| caller\_id    | int      |
| recipient\_id | int      |
| call\_time    | datetime |
+--------------+----------+
(caller\_id, recipient\_id, call\_time) is the primary key for this table.
Each row contains information about the time of a phone call between caller\_id and recipient\_id.
```

Write an SQL query to report the IDs of the users whose first and last calls on **any day** were with **the same person**. Calls are counted regardless of being the caller or the recipient.

Return the result table **in any order**.

The query result format is in the following example:

```
Calls table:
+-----------+--------------+---------------------+
| caller\_id | recipient\_id | call\_time           |
+-----------+--------------+---------------------+
| 8         | 4            | 2021-08-24 17:46:07 |
| 4         | 8            | 2021-08-24 19:57:13 |
| 5         | 1            | 2021-08-11 05:28:44 |
| 8         | 3            | 2021-08-17 04:04:15 |
| 11        | 3            | 2021-08-17 13:07:00 |
| 8         | 11           | 2021-08-17 22:22:22 |
+-----------+--------------+---------------------+
Result table:
+---------+
| user\_id |
+---------+
| 1       |
| 4       |
| 5       |
| 8       |
+---------+
On 2021-08-24, the first and last call of this day for user 8 was with user 4. User 8 should be included in the answer.
Similary, user 4 on 2021-08-24 had their first and last call with user 8. User 4 should be included in the answer.
On 2021-08-11, user 1 and 5 had a call. This call was the only call for both of them on this day. Since this call is the first and last call of the day for both of them, they should both be included in the answer.
```

## ac

```java
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jaywin.gitbook.io/leetcode/solutions/1972-first-and-last-call-on-the-same-day.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
