From 0003e5fcf421fefe3bb3e7f6216a7b143bcb7295 Mon Sep 17 00:00:00 2001 From: ivanbyone Date: Thu, 10 Jul 2025 11:06:24 +0300 Subject: [PATCH] task: #1890 --- README.md | 1 + .../easy/1890. The Latest Login in 2020.sql | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 leetcode/easy/1890. The Latest Login in 2020.sql diff --git a/README.md b/README.md index d7db70e..4face7b 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ Useful for preparing for technical interviews and improving your SQL skills. - [1741. Find Total Time Spent by Each Employee](./leetcode/easy/1741.%20Find%20Total%20Time%20Spent%20by%20Each%20Employee.sql) - [1789. Primary Department for Each Employee](./leetcode/easy/1789.%20Primary%20Department%20for%20Each%20Employee.sql) - [1795. Rearrange Products Table](./leetcode/easy/1795.%20Rearrange%20Products%20Table.sql) + - [1890. The Latest Login in 2020](./leetcode/easy/1890.%20The%20Latest%20Login%20in%202020.sql) - [1965. Employees With Missing Information](./leetcode/easy/1965.%20Employees%20With%20Missing%20Information.sql) - [1978. Employees Whose Manager Left the Company](./leetcode/easy/1978.%20Employees%20Whose%20Manager%20Left%20the%20Company.sql) - [2356. Number of Unique Subjects Taught by Each Teacher](./leetcode/easy/2356.%20Number%20of%20Unique%20Subjects%20Taught%20by%20Each%20Teacher.sql) diff --git a/leetcode/easy/1890. The Latest Login in 2020.sql b/leetcode/easy/1890. The Latest Login in 2020.sql new file mode 100644 index 0000000..0f33c0d --- /dev/null +++ b/leetcode/easy/1890. The Latest Login in 2020.sql @@ -0,0 +1,27 @@ +/* +Question 1890. The Latest Login in 2020 +Link: https://leetcode.com/problems/the-latest-login-in-2020/description/?envType=problem-list-v2&envId=database + +Table: Logins + ++----------------+----------+ +| Column Name | Type | ++----------------+----------+ +| user_id | int | +| time_stamp | datetime | ++----------------+----------+ +(user_id, time_stamp) is the primary key (combination of columns with unique values) for this table. +Each row contains information about the login time for the user with ID user_id. + + +Write a solution to report the latest login for all users in the year 2020. Do not include the users who did not login in 2020. + +Return the result table in any order. +*/ + +SELECT + user_id, + MAX(time_stamp) AS last_stamp +FROM Logins +WHERE time_stamp::varchar LIKE '2020%' +GROUP BY user_id