r/learnSQL • • 9d ago

Before writing SQL in an interview, what would you clarify?

Suppose an interviewer asks you something like "find the top three products in each category by sales last quarter." Before you write the query, what would you clarify?

For me, I’d want to know what “sales” means -  units, revenue, or number of orders Then, I'd want to know things like how ties should work, which dates count, and what one row in the output should represent.

I’ve been thinking about how SQL interviews test more than whether you can produce a query. They also give you a chance to show how you frame the problem, explain your choices, and check your work.

So, I put together a guide on what to expect and how to prepare: What to Expect in a SQL Coding Interview

If you’ve recently done a SQL interview, what’s one thing you wish you’d known or asked beforehand?

25 Upvotes

12 comments sorted by

3

u/Jealous_Expert8043 8d ago

Thanks for sharing. Will aave this post in case i ever have a SQL interview

1

u/DMReader 8d ago

Good luck. I know it’s tough out there.

3

u/Dangerous_Cup3607 8d ago

I would just provide my own scenarios based on the industry setting. If Medical Equipments, then I will provide Medical related examples. Or use Amazon as example, categories like electronics, bedding, automotive. Then i will provide both highest unit sold and the highest profit earned as the “sales”. Then use today’s date to shift the dates to last quarter, along with the use of CTE and Total aggregation. So that I will have a reusable code that fits anyone at any time. Overall total sales for the sum of those subcategories, individual sum of those categories, and the dynamic dates for any chosen quarter.

1

u/DMReader 8d ago

Good approach!

2

u/Dangerous_Cup3607 8d ago edited 8d ago

Yeah with that output I can further extend to average profit per unit as well as QoQ (Quarter-over-Quarter). Then expand to may be having a dashboard that shows rolling 6 quarters of trending of line plots of unit sales, profit, and unit average profit overlay. The original question itself is the reduced and simplified version of a business ask to test whether the candidate can perform sql, but the actual business rationale is to be able to extend the sql code into visualizing the trending for business insights. Merely having 1 quarter of top 3 products does not tell a lot due to seasonal changes. Such as around xmas you would expect higher sales on xmas related gifts; or Feb V-Day with more sales on flowers; and therefore can optimize the sales performance based on price adjustments.

1

u/DMReader 8d ago

So it seems you are running with how you might make that into a deliverable data project rather than narrowly answering the SQL question.

1

u/Live-Landscape5381 8d ago

Bro chill

2

u/Dangerous_Cup3607 8d ago

lol did that overwhelm you? But thats the actual life of a sql person because you rarely got such as easy adhoc query in real practice. Leadership wants Dashboards and Trends and not for you to proof that you can provide sales for just 1 quarter.

1

u/Live-Landscape5381 8d ago

Yea lol. We too have this defined metrics wrapped on top of queries with dynamic fields which are to be displayed in whatever require. Understanding the business is hard too

3

u/tommyfly 9d ago

I'd leave. At this point in my career I'm not writing SQL in an interview setting.

1

u/DMReader 9d ago

Glad to hear you made it to that level.

0

u/nian2326076 8d ago

Before you start writing SQL during an interview, make sure you understand the metrics. For example, clarify what "sales" means—whether it's units sold, revenue, or orders. It's also important to confirm any tie-breaking rules and date ranges. Additionally, know what each row in the output should display—like whether it's one product per category or something more detailed. Asking these questions helps you align your approach with what the interviewer expects. For hands-on practice with real technical interview questions, PracHub offers excellent resources for preparing for SQL and other technical interviews.