SQLSQL
#9

Filter Date Ranges with Rolling Intervals in SQL

MediumSwiggy
Interview Question #9
Asked at Swiggy

Given a `user_activity` table, write a query to return all activity logs recorded in the last 30 days (`activity_time >= CURRENT_DATE - INTERVAL '30 days'`). Return `user_id`, `action`, and `activity_time`.

Input Table: user_activity
2 rows preview
log_iduser_idactionactivity_time
110login2026-08-25 10:00:00
210checkout2026-06-01 12:00:00
Expected Output Structure1 rows
user_idactionactivity_time
10login2026-08-25 10:00:00
Interview Context

Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.

SQLPostgreSQL 15
Ready to execute

Click "Run Query" or press Ctrl + Enter to test your query.

Output will be verified against the test dataset.

Chat with us