Fix the Broken Year Filter Query
Updated
Problem statement
The events table has a name and a timestamp for each event. Names can repeat, and two rows can be exactly the same.
An interviewer shows you this query and says it has errors:
select name MONTH(timestamp)
FROM events
WHEREMONTH(timestamp)>2010The query is meant to return the name and the month of every event that happened after the year 2010. Find the mistakes and write the corrected query.
Return two columns:
namemonth: the month number of the event'stimestamp, from1to12
An event is after 2010 when the year of its timestamp is 2011 or later. Keep one output row for every matching input row, including repeated rows. Return the rows in any order.
PostgreSQL has no MONTH() or YEAR() function. Use EXTRACT(MONTH FROM ...) and EXTRACT(YEAR FROM ...) there.
Table schema
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
events
One row per event. The table has no key, so rows can repeat.
| Column | Type | Nullable | Description |
|---|---|---|---|
| name | Text | No | — |
| timestamp | Timestamp | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| name | Text | No | — |
| month | Integer | No | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
- The
eventstable has from0to10^5rows. - No column is
NULL. - Each
namehas 1 to 20 English letters: one uppercase letter followed by lowercase letters. - Every
timestampis between2000-01-01 00:00:00and2030-12-31 23:59:59, to the second.
More Amazon Onsite Interview questions
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dungeon GameONSITE INTERVIEW · Seen Nov 2026
- Integer BreakONSITE INTERVIEW · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Second Highest SalaryPaytm · PHONE SCREENPaytm interview questions
- Delete Duplicate Employee RecordsInfosys · ONSITE INTERVIEWInfosys interview questions
- Employees Who Earn More Than Their ManagersNykaa · PHONE SCREENNykaa interview questions
- Employees Who Joined More Than a Week AgoNewgen Software · PHONE SCREEN
- Records Created or Updated in a Time WindowPelatro · ONSITE INTERVIEW
- Top Ten Employee SalariesSolytics Partners · ONSITE INTERVIEW
- Departments Without EmployeesDell Technologies · PHONE SCREENDell Technologies interview questions
- Second-Highest Distinct SalaryChubb · PHONE SCREENChubb interview questions
- Find Rows Common to Two TablesSalesforce · PHONE SCREENSalesforce interview questions
- Latest New JobSphere · ONSITE INTERVIEW