← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

SQL-heavy technical screen for a data analyst role at Amazon. Three questions all built on the same session data table, each a bit more involved than the last. Nothing behavioral, just pure querying.

Questions Asked (3)

Q1

Given a table with one row per session and fields for country and session duration in seconds, write a query to find the average session length for sessions longer than 3 minutes.

Product Analytics & Metrics
Author's notes

Straightforward filter and aggregate.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the table schema and confirm that session duration is stored in seconds. Then write a SQL query that filters sessions with duration > 180 seconds and computes the average duration using AVG, ensuring proper handling of NULLs and data types.

Pro tip: Mention that you would check for edge cases like sessions exactly 3 minutes (180 seconds) and decide whether to use > or >= based on business definition. Also, consider if the average should be computed on filtered rows only or if you need to handle missing data.

1. Understand the requirement

Restate the problem: find the average session length for sessions longer than 3 minutes. Confirm that 3 minutes equals 180 seconds and that 'longer than' means strictly greater than 180.

2. Identify the table and columns

Assume a table named 'sessions' with columns 'session_id', 'country', 'duration_seconds'. Clarify if there are any other relevant columns or if the table name is different.

3. Write the SQL query

Use a SELECT statement with AVG(duration_seconds) and a WHERE clause filtering duration_seconds > 180. Optionally, group by country if the question implies per-country averages, but the question asks for overall average.

4. Consider edge cases and performance

Discuss handling of NULL durations, ensuring the column is numeric, and potential indexing on duration_seconds for performance. Also, consider if the average should be rounded or formatted.

5. Validate and explain

Walk through the query logic, explain the filter and aggregation, and mention how you would test it with sample data or edge cases like exactly 180 seconds.

Key Points to Mention

  • Conversion of minutes to seconds (3 minutes = 180 seconds)
  • Use of AVG() aggregate function
  • Filtering with WHERE duration_seconds > 180
  • Handling of NULL values in duration_seconds
  • Potential need for GROUP BY if per-country average is required
  • Performance considerations like indexing on duration_seconds

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Using the same sessions table, how would you produce data for a histogram of session lengths, where each bin represents a 5-minute interval? The output should have one column for the bin and one column for the count of sessions in that bin.

Product Analytics & MetricsData Modeling
Author's notes

This one tripped me up a little.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, compute the duration of each session by subtracting the start time from the end time. Then, bucket the durations into 5-minute intervals using integer division or a floor function, and finally group by the bucket to count the number of sessions in each bin.

Pro tip: Clarify whether the bins should be labeled by the lower bound (e.g., '0-5 min') or by the bin index, and mention that you'd handle edge cases like sessions exactly on a boundary consistently. Also, consider if you need to include empty bins with zero counts for a complete histogram.

1. Calculate session duration

Use the session end time minus start time to get the duration in a consistent unit, such as seconds or minutes. Ensure you handle any NULL or invalid timestamps appropriately.

2. Define bin width and boundaries

Decide that each bin represents a 5-minute interval. Determine how to assign sessions to bins, e.g., using floor(duration_minutes / 5) to get the bin index.

3. Assign each session to a bin

Compute the bin index or label for each session based on its duration. For example, bin_index = FLOOR(duration_seconds / 300) or bin_label = CONCAT(FLOOR(duration_minutes/5)*5, '-', FLOOR(duration_minutes/5)*5+5, ' min').

4. Aggregate counts per bin

Group by the bin index or label and count the number of sessions in each group. Use COUNT(*) or COUNT(session_id).

5. Format and order the output

Select the bin column and the count column, and order by bin to present the histogram in ascending order. Optionally, include bins with zero counts by left joining with a generated series of bins.

Key Points to Mention

  • Use of date/time functions to compute duration (e.g., TIMESTAMPDIFF, DATEDIFF, or EXTRACT(EPOCH FROM ...)).
  • Integer division or floor function to create bins (e.g., FLOOR(duration / 300) for 5-minute bins in seconds).
  • Grouping and counting with GROUP BY and COUNT.
  • Handling of edge cases: sessions exactly on bin boundaries, negative durations, or NULL values.
  • Consideration of empty bins: whether to include them and how to generate them (e.g., using a calendar table or generate_series).
  • Performance considerations: indexing on session start/end times, and avoiding functions on indexed columns if possible.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Still using the sessions table, how would you find pairs of countries where the two countries have a similar number of sessions, defined as within 10% of each other? Output should have one column for each country in the pair.

Product Analytics & MetricsAlgorithms & Data Structures
Author's notes

This is where I had to actually think.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, aggregate the sessions table to get total sessions per country. Then, perform a self-join on the aggregated table where the session counts are within 10% of each other, ensuring each pair is listed once with countries in separate columns. Use a condition like `a.sessions BETWEEN 0.9 * b.sessions AND 1.1 * b.sessions` and `a.country < b.country` to avoid duplicates and self-pairs.

Pro tip: Clarify whether 'within 10%' means 10% of the smaller value or the larger value; in practice, using a symmetric range (e.g., between 90% and 110% of the other) is common, but confirm with the interviewer to avoid ambiguity.

1. Aggregate sessions per country

Write a subquery or CTE that groups the sessions table by country and counts the number of sessions for each country.

2. Self-join on session counts

Join the aggregated table to itself, applying the condition that the session counts are within 10% of each other.

3. Eliminate duplicate and self-pairs

Add a condition like `a.country < b.country` to ensure each pair appears only once and no country is paired with itself.

4. Select the country columns

Output the two country columns, aliasing them appropriately (e.g., country1, country2).

Key Points to Mention

  • Use a self-join on the aggregated session counts per country.
  • Define 'within 10%' precisely: e.g., `a.sessions BETWEEN 0.9 * b.sessions AND 1.1 * b.sessions`.
  • Avoid duplicate pairs by enforcing an ordering condition like `a.country < b.country`.
  • Consider performance: aggregating first reduces the size of the self-join.
  • Handle potential NULLs or zero sessions if necessary.
  • Output should have exactly two columns, one for each country in the pair.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.