Leetcode Problem 1890. The Latest Login in 2020

1890. The Latest Login in 2020

Leetcode Solutions

Using YEAR() and MAX() to Find the Latest Login in

Algorithm

  1. Select the user_id and time_stamp columns from the Logins table.
  2. Use the YEAR() function to filter records where the year of the time_stamp is 2020.
  3. Use the MAX() function to find the latest time_stamp for each user.
  4. Group the results by user_id to ensure each user appears only once with their latest login timestamp.
  5. Alias the MAX(time_stamp) as last_stamp to match the expected output column name.

erDiagram
    Logins {
        int user_id
        datetime time_stamp
        user_id_time_stamp PK
    }

Using EXTRACT() and FIRST_VALUE() to Find the Latest Login in

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...