Ctrl K
Data Analyst · SQL · Mid-level · Theory

You need to get each user's most recent order, and some users have several orders with the same timestamp. How would you write the query, and which function would you choose?

~4 min by voice

How to approach it

This checks whether the candidate knows window functions and understands how ROW_NUMBER, RANK and DENSE_RANK behave on tied values. It also matters whether they can make the result deterministic and filter on the window correctly.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsYou have a query with window functions over a billion-row events table, and it takes forty minutes. How would you investigate, and what would you optimize? SeniorThere's an orders table with the columns created_at and amount. Write a SQL query that finds anomalous days, where the daily revenue differs from the average over the previous seven days by more than three standard deviations. Keep in mind that on some days there were no orders at all. SeniorA query that used to run in milliseconds now takes seconds after the table grew to tens of millions of rows. How would you investigate, and what can you do about it? Mid-levelThere's a sales table with the columns product_id, category, amount, and sold_at. Write a SQL query that, for each category, returns the three products with the highest revenue over the last thirty days, with the revenue total and the rank within the category. Mid-levelWhat are a primary key and a foreign key? And how would you model a many-to-many relationship, for example students and courses? Junior

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~4 min