SQL Query Fundamentals Questions

Core SQL for reading and shaping data: SELECT, filtering with WHERE, sorting, DISTINCT, and single-table aggregation with GROUP BY, HAVING, and aggregate functions. Covers reasoning about NULL handling, grouping semantics, and writing correct queries against a given schema. The baseline query-writing surface most data and engineering interviews open with.

MediumTechnical
50 practiced

Given sales(product_id, sold_date, amount), write a query producing one row per product with a revenue column for each of the last 6 months (columns named YYYY-MM), using conditional aggregation since the engine has no PIVOT function.

MediumTechnical
54 practiced

Using De Morgan's laws, rewrite NOT (status = 'shipped' OR status = 'delivered') into an equivalent WHERE clause that has no top-level NOT. Why can rewriting boolean expressions like this help readability and the optimizer?

EasyTechnical
38 practiced

What is the difference between GROUP BY and DISTINCT? Give one example where either works, and one example where GROUP BY with an aggregate is necessary because DISTINCT alone is insufficient.

EasyTechnical
49 practiced

Given users(user_id, name, country) and orders(order_id, user_id, amount, occurred_at), write a query computing total revenue and distinct-buyer count per country for the last 30 days, including countries with zero revenue (not just zero-activity time periods).

EasyTechnical
47 practiced

Given events(event_id, user_id, event_type, occurred_at), write a query computing Daily Active Users (DAU) for the last 30 full days: count of distinct users per UTC day, treating multiple same-day events per user as one. Compare writing this with COUNT(DISTINCT ...) versus GROUP BY, and note performance considerations at scale.

Unlock Full Question Bank

Get access to all SQL Query Fundamentals interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.