๐๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐๐ฒ๐ฟ:
You have 2 minutes to solve this SQL query.
Find the employees who joined in the last 30 days.
Assume the table structure:
employees(employee_id, employee_name, department, joining_date)
๐ ๐ฒ: Challenge accepted! ๐ช
SELECT
employee_id,
employee_name,
department,
joining_date
FROM employees
WHERE joining_date >= CURRENT_DATE - INTERVAL '30 days';
๐ก Explanation:
This query filters employees whose joining date falls within the last 30 days.
โข CURRENT_DATE returns today's date.
โข INTERVAL '30 days' subtracts 30 days from the current date.
โข The WHERE clause returns employees who joined on or after that date.
This question tests your understanding of:
โ
Date Functions
โ
Date Arithmetic
โ
Filtering Records with Dates
๐ฏ Expected Output Example
Employee Department Joining Date
John IT 2026-06-10
Sarah HR 2026-06-22
๐ Database-Specific Alternatives
MySQL
SELECT *
FROM employees
WHERE joining_date >= CURDATE() - INTERVAL 30 DAY;
SQL Server
SELECT *
FROM employees
WHERE joining_date >= DATEADD(DAY, -30, GETDATE());
Oracle
SELECT *
FROM employees
WHERE joining_date >= SYSDATE - 30;
๐ Tip for SQL Job Seekers:
Date-related SQL questions are very common. Make sure you're comfortable with:
โข Finding records from the last N days
โข Current month/year filters
โข Date differences
โข Date formatting
โข Database-specific date functions
โค๏ธ React with โค๏ธ for more SQL interview challenges!
Post #2907
4.74K
- โค 19