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.

HardTechnical
83 practiced

Given orders(order_id, vendor_id, amount, status) and vendors(vendor_id, name), compute average order value per vendor, but only for completed orders and only for vendors with at least 100 such orders. Write the query, applying the status filter with WHERE (before aggregation) and the count threshold with HAVING (after aggregation), and explain why each belongs where it does.

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?

MediumTechnical
49 practiced

Given orders(order_id, order_date, channel, total_amount), write a query producing monthly revenue with separate online_revenue and in_store_revenue columns, using conditional aggregation (SUM with CASE WHEN).

EasyTechnical
56 practiced

Given orders(order_id, customer_id, order_date, total_amount), write a query returning for each customer: first_order_date, last_order_date, total_orders, and lifetime_value (SUM of total_amount). Why are MIN/MAX useful for customer lifecycle reporting?

EasyTechnical
55 practiced

Explain ROLLUP and CUBE for multi-level aggregation. Using sales(date, region, product, amount), write a single query that produces subtotals by date, by region, and an overall grand total, and explain what the NULLs in the grouping columns of the result mean.

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.