FastPrepFix the Broken Year Filter Query
Problems/Fix the Broken Year Filter Query

Fix the Broken Year Filter Query

Amazon logoAmazon● EasyINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionConstraints

Problem statement

Source note: In an Amazon intern interview, the interviewer showed a short broken query that pulls a name and the month of a timestamp, with a filter that compares against 2010, and asked the candidate to find and fix the errors. The same candidate later said part of the fix is filtering on the year instead of the month.

The report does not give the table, sample rows, or the expected output, and the query used a placeholder table name. Here, the table is called events, the month column is named month, every matching row is kept, and rows can come back in any order.

Our version is about 85% the same as the reported question.

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)>2010

The 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:

  • name
  • month: the month number of the event's timestamp, from 1 to 12

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

MySQLPostgreSQLPandas

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.

ColumnTypeNullableDescription
nameTextNo—
timestampTimestampNo—

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
nameTextNo—
monthIntegerNo—

Row order: any order is accepted. Numeric tolerance: 0.

Constraints

  • The events table has from 0 to 10^5 rows.
  • No column is NULL.
  • Each name has 1 to 20 English letters: one uppercase letter followed by lowercase letters.
  • Every timestamp is between 2000-01-01 00:00:00 and 2030-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

Interview reports that mention this question

  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights