SQL Query for Recent Logins

The table given contains a list of users and when they last logged in. The goal is to write a SQL query that returns the id, username, and password for all users who logged in within the last 24 hours.

Problem

You are given a table with the following structure:
create table logins (
  id int primary key,
  username varchar(255),
  password varchar(255),
  created_at timestamp
);
Write a SQL query that returns the id, username, and password for all users who logged in within the last 24 hours.
Example input: 
logins
id | username | password | created_at
1  | user1    | pwd1     | 2020-01-01 00:00:01
2  | user2    | pwd2     | 2020-01-01 00:00:02
3  | user3    | pwd3     | 2020-01-02 00:00:01
Example output: 
id | username | password
1  | user1    | pwd1
2  | user2    | pwd2

Solution

This solution is in SQL. Our A.I. can create solutions in multiple languages.
by sarastevens
SELECT id, username, password
FROM logins
WHERE created_at >= NOW() - INTERVAL 1 DAY;

/*

The solution above is optimal because it uses the NOW() function to get the current time and subtracts 1 day from it.
This is optimal because it will always return the correct results.

*/

A.I. Evaluation of the Solution

The solution above is optimal because it uses the NOW() function to get the current time and subtracts 1 day from it. This is optimal because it will always return the correct results.

Evaluated at: 2022-11-14 08:15:33