Subqueries Part 1: practice questions
400 questions in four levels, all on RetailMart, the practice database of this course. Write every query yourself, get it wrong, read the error, fix it. That is how it sticks.
Answers are coming soon. Post your query in the WhatsApp Community or Discord and we will check it together.
Easy 100 questions Medium 100 questions Hard 100 questions Crazy 100 questions
Core syntax, applied directly
SUBQUERIES - CONCEPTUAL Q1 What is a subquery - and how is it different from a CTE? Q2 What does "scalar subquery" mean - single row + single column. Q3 Compare IN (subquery) vs EXISTS (subquery). Q4 Why does NOT IN break when the subquery returns NULL? Q5 What is a "correlated subquery"? Q6 Compare = ANY(subquery) vs IN (subquery). Q7 Compare > ALL(subquery) vs > (SELECT MAX...). Q8 Can a subquery in SELECT return multiple rows? Q9 Can a subquery in WHERE return multiple rows? Q10 Compare WHERE col = (subquery) vs WHERE col IN (subquery). Q11 What does (SELECT MAX(net_total) FROM ...) return - type? Q12 When is a subquery in FROM (derived table) required? Q13 Why must a subquery in FROM have an alias? Q14 Compare scalar subquery in SELECT vs JOIN - same result, different style. Q15 What is "semi-join" - and how does EXISTS implement it? Q16 What is "anti-join" - and how does NOT EXISTS implement it? Q17 Why does NOT EXISTS NOT have the NULL problem of NOT IN? Q18 Compare HAVING subquery vs WHERE subquery. Q19 Can a subquery reference its outer query's columns? (Yes if correlated.) Q20 Compare correlated subquery vs LEFT JOIN. Q21 Performance: when does the planner rewrite a subquery to a join? Q22 What is the "subquery cache" in some engines (not in Postgres). Q23 Compare uncorrelated subquery (executes once) vs correlated (executes per row). Q24 Why is "subquery returns more than one row" a common error? Q25 Compare subquery in SELECT vs subquery in WHERE for performance. IN / NOT IN / EXISTS / NOT EXISTS Q26 Find orders with cust_id IN (top 10 customers by spend). Q27 Find customers WHERE customer_id IN (SELECT cust_id FROM sales.orders). Q28 Find customers WHERE customer_id NOT IN (loyalty.members). Q29 Find products WHERE product_id IN (sales.order_items). Q30 Find tickets WHERE cust_id IN (high-spend customers). Q31 Find employees WHERE store_id IN (stores in 'Mumbai'). Q32 Find orders WHERE order_status IN ('Delivered','Cancelled','Returned'). Q33 Find products WHERE brand_id IN (brands of category 'Electronics'). Q34 Find shipments WHERE order_id IN (orders by Gold-tier customers). Q35 Find pay_slips WHERE employee_id IN (employees in 'Sales' dept). Q36 EXISTS: customers who placed orders. Q37 EXISTS: products with reviews. Q38 EXISTS: stores with employees. Q39 EXISTS: warehouses with snapshots. Q40 EXISTS: campaigns with spend. Q41 NOT EXISTS: customers without orders. Q42 NOT EXISTS: products without reviews. Q43 NOT EXISTS: brands without products. Q44 NOT EXISTS: employees without pay_slips. Q45 NOT EXISTS: orders without shipments. Q46 Combine EXISTS + filter: customers who placed > 5 orders. Q47 Combine NOT EXISTS + filter: products with no 5-star reviews. Q48 Compare LEFT JOIN IS NULL vs NOT EXISTS for anti-join. Q49 Use EXISTS inside SELECT (as boolean column). Q50 Use EXISTS in CASE expression. ANY / SOME / ALL Q51 Find products WHERE price > ANY(SELECT price FROM 'electronics'). Q52 Find orders WHERE net_total > ALL(SELECT net_total FROM orders WHERE store_id = 1). Q53 Find customers WHERE tier_id = ANY(SELECT tier_id FROM loyalty.tiers WHERE points > 1000). Q54 Find employees WHERE salary > ALL(SELECT salary FROM stores.employees WHERE role = 'Sales'). Q55 Find reviews WHERE rating < ANY(SELECT rating FROM customers.reviews WHERE product_id = 1). Q56 Find tickets WHERE priority = ANY(ARRAY['Critical','High']). Q57 Find products WHERE brand_id <> ALL(SELECT brand_id FROM dim_brand WHERE category_id = 1). Q58 Find orders WHERE net_total = (SELECT MAX(net_total) FROM sales.orders). Q59 Find products WHERE price = (SELECT MIN(price) FROM products.products). Q60 Find employees WHERE salary = (SELECT MAX(salary) FROM stores.employees WHERE dept_id = 1). Q61 Find orders WHERE net_total > (SELECT AVG(net_total) FROM sales.orders). Q62 Find loyalty members WHERE tier_id > (SELECT MIN(tier_id) FROM loyalty.members). Q63 Find pay_slips WHERE gross_salary > (SELECT AVG(gross_salary) FROM payroll.pay_slips). Q64 Find shipments WHERE delivered_date IS NULL AND shipped_date < (SELECT MIN(shipped_date) + INTERVAL '7 days' FROM ...). Q65 Find products WHERE supplier_id = ANY(SELECT supplier_id FROM products.suppliers WHERE city = 'Mumbai'). Q66 Compare = ANY vs IN - same result. Q67 Compare <> ALL vs NOT IN - same result. Q68 > ANY = greater than at least one. Q69 > ALL = greater than every. Q70 < ANY = less than at least one. Q71 < ALL = less than every. Q72 = SOME = synonym for = ANY. Q73 Combine ANY with array literal: x = ANY(ARRAY[1,2,3]). Q74 ANY with subquery returning 0 rows - what happens. Q75 ALL with subquery returning 0 rows - what happens (TRUE!). SCALAR SUBQUERIES IN SELECT Q76 For each order, show net_total + (SELECT AVG(net_total) FROM sales.orders) AS overall_avg. Q77 For each customer, show (SELECT COUNT(*) FROM sales.orders WHERE cust_id = c.customer_id) AS orders. Q78 For each product, show (SELECT AVG(rating) FROM customers.reviews WHERE product_id = p.product_id) AS avg_rating. Q79 For each store, show (SELECT COUNT(*) FROM stores.employees WHERE store_id = s.store_id) AS emp_count. Q80 For each campaign, show (SELECT SUM(amount) FROM marketing.ads_spend WHERE campaign_id = c.campaign_id) AS total_spend. Q81 For each region, show count of stores via scalar subquery. Q82 For each customer, show last order date. Q83 For each product, show last review date. Q84 For each employee, show last pay_slip month. Q85 For each ticket, show count of comments via scalar subquery. Q86 For each customer, show their tier_name via scalar subquery JOIN. Q87 For each order, show the customer's full_name. Q88 For each order, show the store's region_name. Q89 For each ticket, show the agent's full_name. Q90 For each shipment, show the order's customer email. Q91 Use scalar subquery in WHERE: WHERE net_total > (subq). Q92 Use scalar subquery in HAVING: HAVING SUM(amt) > (subq). Q93 Use scalar subquery in ORDER BY: ORDER BY (SELECT ...). Q94 Use scalar subquery in CASE: CASE WHEN x > (subq) THEN ... END. Q95 Multiple scalar subqueries in one SELECT (5 columns). Q96 Show "% of total revenue" per region using scalar denominator. Q97 Show "rank among peers" via correlated scalar subquery. Q98 Show "is_above_average" boolean column. Q99 Show "how far from max" - (max - this). Q100 Show "10 customer KPIs" all as scalar subqueries in one SELECT. Combined ideas, multi-step thinking
SUBQUERIES DEEPER - CONCEPTUAL Q1 Why is a correlated subquery slower than an uncorrelated one? Q2 When does the planner rewrite a subquery to a JOIN? Q3 Compare derived table (FROM subquery) vs CTE. Q4 Why is "subquery returns more than one row" common with =? Q5 Explain LIMIT 1 inside a subquery - when needed. Q6 Why use ORDER BY inside subquery with LIMIT 1? Q7 Compare uncorrelated EXISTS (constant) vs correlated EXISTS. Q8 Compare WHERE x IN (...) vs WHERE x = ANY(VALUES (...)). Q9 Compare WHERE x IN (subq) vs JOIN ... - same result, different plan. Q10 When does NOT IN return 0 rows surprisingly? Q11 Why is NOT EXISTS NULL-safe? Q12 Compare SELECT scalar vs JOIN aggregate - fan-out implications. Q13 Why is "subquery in FROM" called a "derived table" or "inline view"? Q14 Explain "lateral subquery" vs "subquery in FROM". Q15 Compare HAVING WHERE filter vs subquery. Q16 Why must derived tables have aliases? Q17 Compare HAVING SUM(x) > (subq) vs WHERE (with pre-aggregate). Q18 What is "subquery flattening"? Q19 Why does putting an aggregate in WHERE error? Q20 Compare scalar subquery in SELECT vs adding to GROUP BY. Q21 What is "subquery factoring" - same as CTE. Q22 Explain why subqueries in SELECT can hide N+1 query patterns. Q23 Compare subquery in WHERE = (single value) vs IN (set). Q24 Why does ORDER BY with scalar subquery hurt performance. Q25 Walk through how planner decides Hash Semi-Join vs Nested Loop. IN / EXISTS DEEPER Q26 Find customers with orders AND reviews - combine 2 EXISTS. Q27 Find customers with orders BUT no reviews. Q28 Find customers with orders in 2024 AND 2025. Q29 Find products with reviews in last 30 days AND price > 1000. Q30 Find stores with employees AND orders AND inventory. Q31 Find brands present in BOTH 'Electronics' AND 'Apparel' categories. Q32 Find customers in cities WITH at least one store. Q33 Find products of suppliers in 'Mumbai' AND shipped in last 60 days. Q34 Find tickets created by customers with > 5 orders. Q35 Find pay_slips for employees in stores with > 10 employees. Q36 Find orders by customers who are loyalty members. Q37 Find orders by customers WHO are NOT loyalty members. Q38 Find products in categories with > 100 products. Q39 Find products in brands with avg_price > 5000. Q40 Find customers in tiers with > 1000 members. Q41 Find orders shipped by couriers with avg_delivery_time < 3 days. Q42 Find ad spend rows for campaigns active in March 2025. Q43 Find reviews on products with > 5 sales. Q44 Find tickets on products that have ever been returned. Q45 Find calls regarding products with low ratings. Q46 Find page_views in sessions that ended with a purchase. Q47 EXISTS with multiple correlated columns. Q48 NOT EXISTS for a complex predicate (subquery JOIN). Q49 Nested EXISTS: customers who reviewed products they returned. Q50 EXISTS + DISTINCT - when redundant. SUBQUERY IN FROM (DERIVED TABLE) Q51 Derived table: (SELECT cust_id, SUM(net_total) AS total FROM orders GROUP BY cust_id) AS s. Q52 Filter derived: WHERE total > 50000. Q53 Join derived with customers. Q54 Join 3 derived tables. Q55 Top-N from a derived. Q56 Derived with GROUP BY + HAVING. Q57 Derived with window function (preview). Q58 Derived with UNION ALL. Q59 Derived with EXCEPT. Q60 Derived returning multiple columns. Q61 Derived using DISTINCT ON. Q62 Derived used in CASE expression. Q63 Derived used in scalar context. Q64 Derived used twice - performance implications. Q65 Derived inside another derived (nested). Q66 Subquery with ORDER BY + LIMIT for top-N. Q67 Subquery in LEFT JOIN. Q68 Subquery in RIGHT JOIN. Q69 Subquery in FULL OUTER JOIN. Q70 Subquery aliasing columns explicitly. Q71 Derived used in window function PARTITION BY. Q72 Derived with no GROUP BY but aggregate. Q73 Replace nested derived with CTE - same result, more readable. Q74 Derived returning JSON. Q75 Derived built from a UNION across schemas. HAVING WITH SUBQUERY Q76 HAVING SUM(net_total) > (SELECT AVG(SUM(net_total)) FROM ...). Q77 HAVING COUNT(*) > (SELECT AVG count) - find above-average. Q78 HAVING SUM > 10 x AVG. Q79 HAVING SUM > 2 x prior period. Q80 HAVING with EXISTS. Q81 HAVING with NOT EXISTS. Q82 HAVING with correlated subquery. Q83 HAVING based on another table's stats. Q84 HAVING with multiple conditions (AND/OR). Q85 HAVING comparing two aggregates from same query. Q86 HAVING per-region: revenue > region's avg. Q87 HAVING per-category: AVG > overall AVG. Q88 HAVING with CASE-based COUNT. Q89 HAVING for outlier detection. Q90 HAVING SUM(qty FILTER WHERE) > N. Q91 HAVING with date-based subquery. Q92 HAVING + GROUP BY ROLLUP. Q93 HAVING + GROUP BY CUBE. Q94 HAVING + complex CASE in COUNT. Q95 HAVING + percentile threshold. Q96 HAVING + median threshold. Q97 HAVING + max threshold. Q98 HAVING + min threshold. Q99 HAVING + COUNT distinct > N. Q100 Combine HAVING + subquery + window + ROLLUP in one mega query. Interview grade, edge cases
SUBQUERY REWRITES Q1 Rewrite IN-subquery as JOIN. Q2 Rewrite NOT IN as NOT EXISTS (NULL-safe). Q3 Rewrite correlated subquery as LEFT JOIN. Q4 Rewrite scalar subquery in SELECT as LEFT JOIN. Q5 Rewrite EXISTS as INNER JOIN + DISTINCT. Q6 Rewrite multiple scalar subqueries as a single CTE. Q7 Rewrite "(SELECT MAX...)" as window function. Q8 Rewrite "WHERE x = (subquery)" with DISTINCT ON. Q9 Rewrite "WHERE x IN (top-N)" as LATERAL. Q10 Rewrite HAVING subquery to a WHERE on aggregated CTE. Q11 Rewrite multi-level nested subquery as flat CTE chain. Q12 Rewrite "for each row, count related" via window. Q13 Rewrite correlated MAX subquery as window. Q14 Rewrite "find rows with same key" via window. Q15 Rewrite "find latest per group" via DISTINCT ON or ROW_NUMBER. Q16 Rewrite EXISTS subquery as LEFT JOIN ... IS NOT NULL. Q17 Rewrite NOT EXISTS as LEFT JOIN ... IS NULL. Q18 Rewrite OR-subquery as UNION ALL. Q19 Rewrite AND-of-subqueries as INNER JOIN chain. Q20 Rewrite "Top-N per group" subquery as LATERAL. Q21 Rewrite "find duplicates" subquery as window count. Q22 Rewrite "find gaps" subquery as window LAG. Q23 Rewrite "find islands" subquery as window. Q24 Rewrite "find runs" subquery as gaps-and-islands. Q25 Rewrite percent-of-total subquery using window. PERFORMANCE FORENSICS Q26 EXPLAIN ANALYZE a correlated subquery. Q27 EXPLAIN ANALYZE the same query rewritten as JOIN - compare. Q28 EXPLAIN IN-subquery vs JOIN - same plan? Q29 EXPLAIN scalar subquery in SELECT - see the per-row subplan. Q30 Identify "SubPlan" node in EXPLAIN. Q31 Identify "InitPlan" node (uncorrelated subquery). Q32 Identify "Hash Semi Join" for IN-subquery. Q33 Identify "Hash Anti Join" for NOT EXISTS. Q34 Add index to speed up correlated subquery. Q35 Add composite index for two-column correlated subquery. Q36 Add expression index for subquery filter. Q37 Pre-aggregate via CTE to reduce subquery cost. Q38 Materialize CTE explicitly to control plan. Q39 Use LATERAL to replace expensive correlated subquery. Q40 Use WINDOW to replace expensive subquery in SELECT. Q41 Use SET enable_nestloop = off to see hash-based plan. Q42 Compare plan with and without random_page_cost tuning. Q43 Tune work_mem to keep hash in memory. Q44 Diagnose "subquery returns more than one row" error. Q45 Add LIMIT 1 + ORDER BY for safe scalar subquery. Q46 Diagnose "subquery used in expression must return single column" error. Q47 Diagnose "subquery in FROM must have an alias" error. Q48 Write an IN-subquery query pattern (in prod, pg_stat_statements finds the slow ones). Q49 Track "N+1" via repeated subqueries from app logs. Q50 Audit slow queries with subqueries - top 10. ANTI-PATTERN CATALOG Q51 ANTIPATTERN: NOT IN with nullable subquery. Q52 ANTIPATTERN: scalar subquery in SELECT for every row of huge table. Q53 ANTIPATTERN: correlated subquery instead of JOIN. Q54 ANTIPATTERN: SELECT (subquery) in app loop (N+1). Q55 ANTIPATTERN: subquery in WHERE without index. Q56 ANTIPATTERN: ORDER BY (subquery) - re-evaluated per row. Q57 ANTIPATTERN: DISTINCT after EXISTS - redundant. Q58 ANTIPATTERN: EXISTS (SELECT col FROM ...) - col evaluation wasted. Q59 ANTIPATTERN: IN-subquery with 100k values - slow. Q60 ANTIPATTERN: WHERE col IN (SELECT col FROM same_table) - likely just need DISTINCT. Q61 ANTIPATTERN: triple-nested correlated subquery. Q62 ANTIPATTERN: subquery + ORDER BY without LIMIT - wasted sort. Q63 ANTIPATTERN: subquery materialized when it should be inlined. Q64 ANTIPATTERN: NOT EXISTS with FROM cross product. Q65 ANTIPATTERN: HAVING with full table scan inside. Q66 ANTIPATTERN: subquery returning entire JSON instead of needed field. Q67 ANTIPATTERN: hardcoded IN-list when JOIN to table is cleaner. Q68 ANTIPATTERN: subquery in CASE that fires N times. Q69 ANTIPATTERN: scalar subquery returning whole row (use composite type). Q70 ANTIPATTERN: GROUP BY + subquery + window - overcomplicated. Q71 ANTIPATTERN: subquery using SELECT * (wasted columns). Q72 ANTIPATTERN: nested derived tables with redundant aliases. Q73 ANTIPATTERN: WHERE x = ANY(subq) used as anti-join. Q74 ANTIPATTERN: subquery in DELETE / UPDATE without WHERE. Q75 ANTIPATTERN: subquery without ORDER BY in LIMIT 1. REAL-WORLD PRODUCTION PATTERNS Q76 Build "find duplicate customers by email" - subquery + GROUP BY. Q77 Build "find orphan order_items" - anti-join. Q78 Build "find late shipments" - correlated date subquery. Q79 Build "above-average customers" report. Q80 Build "below-median orders" report. Q81 Build "high-LTV customer" segment. Q82 Build "low-velocity products" report. Q83 Build "high-priority unresolved tickets" report. Q84 Build "premium tier upgrade candidates" - multi-criteria subquery. Q85 Build "stale inventory" report - subquery on snapshot dates. Q86 Build "churn-risk" report - subquery on last_order. Q87 Build "high-spending guests" - anti-join on loyalty. Q88 Build "fraud watchlist" - subquery on velocity + amount. Q89 Build "agent leaderboard" - subquery on tickets resolved. Q90 Build "supplier compliance" - anti-join on shipments missed. Q91 Build "campaign effectiveness" - subquery on attributions. Q92 Build "warehouse health" - subquery on snapshot age. Q93 Build "courier reliability" - subquery on late deliveries. Q94 Build "category trend" - month-over-month subquery. Q95 Build "brand growth" - subquery comparing periods. Q96 Build "tier migration" - subquery on prior tier. Q97 Build "loyalty churn" - anti-join on member activity. Q98 Build "executive scorecard" - 20 metric subqueries in 1 row. Q99 Build "data quality" - subquery on NULL counts per table. Q100 Build "anomaly detection" - subquery on z-score. Production scenarios, optimisation
SUBQUERY + WINDOW Q1 Top-N per group via DISTINCT ON + subquery. Q2 Top-N per group via ROW_NUMBER. Q3 Top-3 customers per region. Q4 Top-5 products per category. Q5 Top-10 stores per region. Q6 Top-N + tiebreaker via composite ORDER BY. Q7 Per row, percent of group total via window. Q8 Per row, percent of grand total via subquery + window. Q9 Running total per group. Q10 Year-over-year growth via window. Q11 Quarter-over-quarter growth. Q12 Month-over-month. Q13 Customer lifetime: window of all orders. Q14 RFM bucket via NTILE + subquery. Q15 NTILE quartile of order_total. Q16 Median per group via percentile_cont. Q17 Top-3 cheapest per category. Q18 Top-3 most expensive per category. Q19 Per region, customer with biggest spend. Q20 Per category, brand with most products. Q21 Per store, top employee by tickets resolved. Q22 Per courier, longest shipment. Q23 Per warehouse, oldest snapshot. Q24 Per supplier, latest shipment. Q25 Per agent, top-rated call. MULTI-SOURCE SUBQUERIES Q26 Customer 360deg: orders + reviews + tickets + calls + returns + page_views. Q27 Product 360deg: sold + reviewed + returned + in inventory. Q28 Store 360deg: employees + orders + revenue + complaints. Q29 Region 360deg. Q30 Campaign 360deg. Q31 Employee 360deg. Q32 Brand 360deg. Q33 Supplier 360deg. Q34 Tier 360deg. Q35 Agent 360deg. Q36 Per customer, union of all touchpoints. Q37 Per product, union of all events. Q38 Per region, union of all sales channels. Q39 Per campaign, union of attribution sources. Q40 Per warehouse, union of inventory changes. Q41 Per supplier, union of orders shipped. Q42 Per courier, union of deliveries + failures. Q43 Per tier, union of upgrades + downgrades. Q44 Per agent, union of tickets + calls. Q45 Per page_view, enrich with customer + product. Q46 Cross-schema EXISTS chain. Q47 Cross-schema NOT EXISTS for orphan detection. Q48 Cross-domain JOIN via subqueries. Q49 Cross-domain aggregation via UNION ALL of subqueries. Q50 Cross-domain anti-join via EXCEPT. SUBQUERY IN DML (25) NOTE: RetailMart is READ-ONLY - run these DML statements in your OWN practice database, or preview the affected rows with a SELECT first (the answer key shows the SELECT preview against RetailMart). Q51 UPDATE orders SET status = 'reviewed' WHERE order_id IN (subquery). Q52 UPDATE customers SET tier = (the customer's loyalty tier, via subquery). Q53 DELETE old_orders WHERE order_id IN (subquery). Q54 INSERT INTO archive SELECT * FROM ... WHERE ... (subquery filter). Q55 UPDATE products SET stock = (subquery from inventory). Q56 UPDATE employees SET salary = salary * 1.1 WHERE dept_id IN (subquery). Q57 DELETE customers.customers WHERE customer_id NOT IN (subquery). Q58 INSERT INTO audit_log SELECT order_id FROM sales.orders WHERE ... (subquery filter). Q59 UPDATE tickets SET status = 'closed' WHERE created_date < (subquery date). Q60 UPDATE ad_campaigns SET active = false WHERE id IN (subquery low spend). Q61 CREATE TABLE high_value AS SELECT * FROM sales.orders WHERE net_total > (subq). Q62 ALTER TABLE ADD COLUMN tier_id DEFAULT (subquery)? Show how (immutable required). Q63 UPSERT customers using a subquery for the new tier. Q64 MERGE INTO ... USING (subquery) ... Q65 Bulk INSERT via subquery (INSERT SELECT). Q66 Subquery-driven UPDATE setting multiple columns. Q67 Subquery in WITH for CTE-based DML. Q68 Subquery in RETURNING. Q69 UPDATE ... FROM (subquery). Q70 DELETE ... USING (subquery). Q71 CTE-DML chain: WITH d AS (DELETE ...) INSERT INTO archive SELECT * FROM d. Q72 UPDATE with subquery to compute new value per row. Q73 Conditional UPDATE: WHERE (subquery) IS DISTINCT FROM new_value. Q74 DELETE with subquery and LIMIT (batched). Q75 INSERT INTO ... SELECT from JOIN of multiple subqueries. REAL REPORTS Q76 "Above average" report per region. Q77 "Below median" report per category. Q78 "Top quartile" customers. Q79 "Bottom quartile" products. Q80 "Outlier orders" via z-score. Q81 "Cohort retention" via subquery on signup month. Q82 "Churn analysis" with subquery on last activity. Q83 "Win-back targets" - lapsed customers. Q84 "Tier movers" - upgraded recently. Q85 "Loyalty new members". Q86 "Inventory at risk" - subquery on velocity vs stock. Q87 "Stockout candidates" - qty < forecast. Q88 "Supplier scorecard" - multi-metric subqueries. Q89 "Courier scorecard". Q90 "Campaign ROI". Q91 "Brand performance vs peers". Q92 "Top 10% products by revenue". Q93 "Bottom 10% products by sales velocity". Q94 "VIP customers" - multi-criteria. Q95 "Fraud watchlist" - subquery on velocity + amount. Q96 "SLA breach" - subquery on response time. Q97 "Stuck tickets" - open for > p95 time. Q98 "Reactivation candidates" - last_order in 60-180 days. Q99 "Refund risk" - subquery on customer return rate. Q100 "Executive 1-pager" - 50 metrics from subqueries in one row.