Aggregates and Grouping: 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
AGGREGATE / GROUP BY - CONCEPTUAL Q1 Difference between COUNT(*) and COUNT(column_name). Q2 What does COUNT(DISTINCT col) return? Q3 Does AVG include NULLs in the denominator? Why does it matter? Q4 What does SUM return on an empty result set - 0 or NULL? Q5 Difference between WHERE and HAVING - give an example of each. Q6 Why can't WHERE filter on COUNT(*)? Q7 Rule: every non-aggregated SELECT column must appear in GROUP BY - why? Q8 What is STRING_AGG and when is it useful? Q9 Does STRING_AGG respect order? How do you control the order of concatenation? Q10 Why is MIN/MAX valid on dates and strings, not just numbers? SINGLE-NUMBER AGGREGATES (NO GROUP BY) Q11 How many customers does RetailMart have? Q12 How many orders has RetailMart processed in total? Q13 How many delivered orders? (filter then COUNT). Q14 How many customer reviews exist? Q15 How many distinct cities do stores operate in? Q16 How many distinct order_status values are in sales.orders? Q17 How many distinct customer tiers exist? Q18 How many products have a price above 1000? Q19 How many tickets are currently 'Open'? Q20 How many support tickets have NEVER been resolved? Q21 What is the TOTAL revenue across all delivered orders? (SUM net_total). Q22 What is the AVERAGE order net_total across all orders? Q23 What is the AVERAGE salary across all employees? Q24 What is the AVERAGE product price across the catalog? Q25 What is the AVERAGE customer review rating? Q26 What is the highest salary in the company? Q27 What is the lowest salary in the company? Q28 What is the most expensive product price? Q29 What is the cheapest product price (above 0)? Q30 What is the LATEST order date in sales.orders? Q31 What is the EARLIEST order date in sales.orders? Q32 What is the AVERAGE call_duration_seconds across all calls? Q33 What is the MAX refund_amount in sales.returns? Q34 What is the SUM of all marketing.campaigns budgets? Q35 What is the AVERAGE finance.expenses amount? Q36 What is the TOTAL finance.expenses amount for 2025? Q37 What is the SUM of all payroll.pay_slips.net_salary? (Total salary payout.) Q38 What is the MAX loyalty.members.points_balance? Q39 What is the MIN loyalty.members.points_balance? Q40 Get all 5 stats (count, sum, avg, min, max) of net_total on sales.orders in one row. GROUP BY - SINGLE COLUMN Q41 Count orders per order_status (sales.orders). Q42 Count customers per tier (customers.customers). Q43 Count tickets per priority. Q44 Count tickets per status. Q45 Count page_views per device_type. Q46 Count application_logs per level. Q47 Count api_requests per method. Q48 Count api_requests per status_code (interesting distribution). Q49 Count employees per role. Q50 Count stores per city. Q51 Count products per brand_id. Q52 Count reviews per rating (1 through 5). Q53 Count returns per reason. Q54 Count ads_spend rows per platform. Q55 SUM net_total per order_status. Q56 SUM salary per role (employees). Q57 AVG net_total per order_status. Q58 AVG salary per dept_id (employees). Q59 AVG rating per category in support tickets. Q60 SUM budget per campaign month (DATE_TRUNC('month', start_date)). Q61 Count orders per order_date month (DATE_TRUNC('month', order_date)). Q62 Count customers per registration year (EXTRACT(YEAR FROM registration_date)). Q63 Count calls per call_reason. Q64 SUM call_duration_seconds per agent_id (which agent talks the most?). Q65 Count attendance entries per employee_id. Q66 Count tickets per customer_id. Q67 SUM refund_amount per return reason. Q68 SUM amount per exp_cat_id (finance.expenses). Q69 MAX salary per dept_id. Q70 MIN price per brand_id. HAVING + STRING_AGG Q71 List order statuses with more than 1,000 orders (GROUP BY ... HAVING COUNT > 1000). Q72 List cities with more than 5 stores (HAVING COUNT > 5). Q73 List tiers with more than 5,000 customers. Q74 List brands with more than 100 products. Q75 List employee roles with more than 50 people. Q76 List rating values where there are 1000+ reviews. Q77 List call_reasons with more than 500 calls. Q78 List page_view device_types with more than 100,000 views. Q79 List api_request methods with more than 1,000 hits. Q80 List ticket priorities where >= 1000 tickets exist. Q81 Per role, only roles whose AVG salary > 50000. Q82 Per brand_id, only brands whose AVG product price > 1000. Q83 Per order_status, only statuses whose SUM net_total > 1,000,000. Q84 Per registration year, only years with > 5,000 new customers. Q85 Per month, only months with more than 5,000 orders. Q86 Per dept_id, only departments where SUM salary > 10,000,000. Q87 Per campaign month, only months with total budget > 1,000,000. Q88 Per platform (ads_spend), only platforms with SUM amount > 1,000,000. Q89 Per category (tickets), only categories with more than 500 tickets. Q90 Per exp_cat_id, only categories with sum amount > 5,000,000. Q91 STRING_AGG: comma-separated list of distinct order_status from sales.orders. Q92 STRING_AGG: comma-separated list of distinct cities from stores.stores. Q93 STRING_AGG: comma-separated list of distinct tiers from customers.customers, alphabetised. Q94 STRING_AGG: per role, list ALL employee first_names joined by ', '. Q95 STRING_AGG DISTINCT: per call_reason, distinct status values. Q96 STRING_AGG: per priority, all ticket subjects (LIMIT to a small group). Q97 STRING_AGG: per device_type, distinct OS values (web_events.page_views). Q98 STRING_AGG: per dept_id, list of employee first names ordered alphabetically. Q99 STRING_AGG: per brand_id, list of product names (might be long - verify on a small sample). Q100 STRING_AGG with ORDER BY inside: per ticket category, subjects ordered by created_date. Combined ideas, multi-step thinking
AGGREGATE DEEPER - CONCEPTUAL Q1 Difference between COUNT(*), COUNT(col), COUNT(DISTINCT col) - give a row-set example for each. Q2 Why does SUM(CASE WHEN x = 'A' THEN amount END) work for filtered sums while WHERE doesn't (in the same statement)? Q3 Compare AVG(col) vs AVG(COALESCE(col, 0)) - when do they give different answers? Q4 What's the difference between SUM(amount) and SUM(DISTINCT amount)? Q5 Explain what FILTER (WHERE ...) does - and how it compares to CASE inside aggregates. Q6 What happens to SUM/AVG/COUNT when the WHERE eliminates ALL rows - is the result NULL or 0? Q7 Why must non-aggregated columns appear in GROUP BY? Show what happens if you forget. Q8 Can you GROUP BY an expression (DATE_TRUNC(...))? Show example. Q9 Compare GROUP BY col vs GROUP BY 1 - when is each safer? Q10 Explain HAVING vs WHERE again - but with a CASE-driven aggregate example. Q11 What does GROUP BY ROLLUP(a, b) produce that GROUP BY a, b does not? Q12 Compare GROUP BY CUBE vs GROUP BY ROLLUP - which produces MORE subtotal rows? Q13 What is GROUPING SETS - and when do you need it over CUBE/ROLLUP? Q14 Explain the GROUPING() function - what does GROUPING(col) return for subtotal rows? Q15 Why is SELECT col, COUNT(*) FROM t without GROUP BY an error if col isn't aggregated? Q16 Can ORDER BY reference an aggregate alias? Compare with HAVING. Q17 What's the difference between PERCENTILE_CONT and PERCENTILE_DISC? (Brief - full coverage Topic 22.) Q18 Why is GROUP BY on a TIMESTAMP column rarely useful - and what's the standard fix? Q19 What does ARRAY_AGG do - give a use case. Q20 Difference between STRING_AGG and ARRAY_AGG. Q21 What does JSON_AGG produce - and when is it useful for APIs? Q22 Why does COUNT(*) often outperform COUNT(col) in PostgreSQL? Q23 Explain the "1 + GROUP BY trick" (SELECT 1 FROM t GROUP BY ...). When is this used? Q24 What is BIT_AND / BIT_OR / BOOL_AND / BOOL_OR? Give a use case for BOOL_OR. Q25 Why is GROUP BY + ORDER BY + LIMIT often a complete reporting unit? CONDITIONAL AGGREGATION Q26 Per order_status: COUNT(*) AND SUM(net_total) in one row using GROUP BY. Q27 Single-row summary: COUNT(*) for each status using SUM(CASE WHEN status='X' THEN 1 END). Q28 Total delivered revenue + total cancelled count in ONE row using conditional SUM/COUNT. Q29 Per customer tier, count customers AND average tenure in years. Q30 Per ticket priority, count tickets + average resolution time in hours. Q31 Per device_type, count page_views + count distinct customer_id (excludes NULL anonymous). Q32 Per role, count employees + average salary + max salary + min salary. Q33 Per call_reason, count + average call_duration + count of long calls (> 300s). Q34 Per brand_id, count products + count premium products (price > 1000) + average price. Q35 Per category (support tickets), count + percent resolved (use CASE + COUNT). Q36 Per registration year, count new customers + count of Gold/Platinum. Q37 Per region, count stores + count distinct cities. Q38 Single row: count distinct customer_ids in sales.orders AND in customers.reviews AND in support.tickets. Q39 Single row: count of orders by status using FILTER (WHERE ...) - 4 columns: delivered_count, cancelled_count, pending_count, total_count. Q40 Per platform (ads_spend), SUM amount + COUNT rows + AVG amount per spend record. Q41 Per ad campaign month, SUM ad spend + COUNT campaigns active. Q42 Per exp_cat_id, SUM amount + COUNT + AVG + STDDEV (variance check on expenses). Q43 Per pay_slip salary_month, SUM gross_salary + SUM net_salary + SUM income_tax. Q44 Per work_order line_id, SUM quantity_produced + SUM rejected_quantity + rejection rate %. Q45 Per warehouse, SUM quantity_on_hand from inventory_snapshots (latest snapshot only). Q46 Per supplier_id, COUNT products + AVG price + MAX price + MIN price. Q47 Per loyalty tier, COUNT members + AVG points_balance + MAX points_balance. Q48 Per support category, percentage of Open tickets (FILTERED count / total). Q49 Per page_view URL, count distinct customer_id + count distinct session_id. Q50 Per device_type + os combination, COUNT page_views. MULTI-COLUMN GROUP BY + DATE BUCKETS Q51 Per order_status AND month, COUNT orders + SUM net_total. Q52 Per customer tier AND registration year, COUNT customers. Q53 Per ticket priority AND status, COUNT tickets. Q54 Per device_type AND month, COUNT page_views. Q55 Per platform AND month, SUM ads_spend amount. Q56 Per role AND store_id, COUNT employees + AVG salary. Q57 Per brand_id AND is_premium (price > 1000), COUNT products. Q58 Per call_reason AND status, COUNT calls + SUM duration. Q59 Per campaign year AND quarter, SUM budget. Q60 Per shipment courier_name AND month, COUNT shipments. Q61 Per attendance year AND month, COUNT records + SUM (check_out - check_in) duration. Q62 Per orders status AND store, COUNT + SUM net_total. Q63 Per customer city AND tier, COUNT customers. Q64 Per refund reason AND month, COUNT returns + SUM refund_amount. Q65 Per priority AND week (DATE_TRUNC('week', created_date)), COUNT tickets. Q66 Per HTTP method AND status_code class (2xx/3xx/etc.), COUNT api_requests. Q67 Per app log level AND service_name, COUNT logs. Q68 Per region AND week, COUNT stores opened. Q69 Per fiscal_quarter (custom CASE) + brand_id, COUNT products. Q70 Per shift (CASE on EXTRACT(HOUR)) + day_of_week, COUNT calls. Q71 Per supplier_id + warehouse_id, SUM quantity from supply_chain.shipments. Q72 Per work_orders.line_id + status, COUNT + SUM quantity_produced. Q73 Per exp_cat_id + month, SUM amount. Q74 Per loyalty.tier_id + month-of-join, COUNT members. Q75 Per pay_slip salary_year + salary_month, SUM gross_salary across all employees. HAVING / FILTER / GROUPING SETS Q76 Show order_statuses with > 1000 orders AND SUM(net_total) > 5,000,000 (multi-condition HAVING). Q77 Show customers (GROUPed by customer_id from orders) who placed > 10 orders. Q78 Show product_ids in order_items with SUM(quantity) > 100. Q79 Show employees with SUM(salary across pay_slips) > 1,000,000 (HAVING on aggregated payroll). Q80 Show platforms in ads_spend with AVG(amount) > 5000 and COUNT > 10. Q81 Show brands with > 50 products AND AVG(price) BETWEEN 1000 AND 10000. Q82 Show stores in cities with COUNT >= 3 stores (cities to consolidate). Q83 Show tier_id from loyalty.members with > 1000 members AND AVG(points_balance) > 500. Q84 Show categories of tickets with COUNT > 500 AND resolution_rate < 50% (HAVING using CASE-COUNT ratio). Q85 Show months with > 10000 orders AND SUM(net_total) > 50,000,000. Q86 Using FILTER: count orders per status in a single row (Delivered, Cancelled, Pending, etc.) Q87 Using FILTER: count distinct customers per tier in one row of 4 columns. Q88 Using FILTER: SUM revenue per region in one row. Q89 Using ROLLUP: per order_status and month, SUM + subtotals per status + grand total. Q90 Using CUBE: per device_type AND os, COUNT page_views + all subtotals + grand total. Q91 Using GROUPING SETS: separately group by (tier) AND (registration_year) - two reports in one query. Q92 ROLLUP on (dept_id, role) for employee counts. Q93 Use GROUPING() to identify subtotal rows in a ROLLUP output. Q94 Combine FILTER + GROUP BY: per region, count delivered orders AND cancelled orders. Q95 Per platform, SUM amount FILTER WHERE spend_date >= '2025-01-01'. Q96 Per product brand, count of 5-star reviews (FILTER WHERE rating = 5). Q97 Use STRING_AGG with GROUP BY: per category, comma-separated list of ticket subjects (latest 5). Q98 Per region, top-3 stores by SUM(net_total) - needs a window function (peek at Topic 16). Q99 Per customer tier, MAX, MIN, AVG of points_balance from loyalty.members. Q100 Per ticket category, percent of tickets handled by 'High' priority + percent by 'Critical' - using FILTER counts divided by total. Interview grade, edge cases
AGGREGATES - CONCEPTUAL Q1 Compare PERCENTILE_CONT vs PERCENTILE_DISC - which interpolates? Q2 Why does median require WITHIN GROUP (ORDER BY ...)? Q3 What is an "ordered-set aggregate" in PostgreSQL? Q4 Explain how PERCENTILE_CONT(0.5) computes median for even-count groups (interpolates). Q5 Compare MODE() WITHIN GROUP vs custom CASE-COUNT logic. Q6 What does ROLLUP(a, b, c) produce - listed subtotals. Q7 What does CUBE(a, b, c) produce - all 2^3 subtotal combinations. Q8 GROUPING SETS - when is it more flexible than CUBE/ROLLUP? Q9 GROUPING(col) function - how to read 1/0 in subtotal rows. Q10 ARRAY_AGG(col ORDER BY ...) - what's stored vs unordered? Q11 STRING_AGG(col, ',' ORDER BY col) - when ORDER BY is non-deterministic. Q12 JSON_AGG vs JSONB_AGG - when each. Q13 JSONB_OBJECT_AGG - build a key->value map from rows. Q14 ARRAY_AGG(DISTINCT col) - when DISTINCT matters. Q15 SUM(DISTINCT col) - uncommon but valid case. Q16 Explain FILTER WHERE - when this is cleaner than CASE WHEN ... THEN ... END. Q17 Multi-FILTER in one aggregate row: COUNT(*) FILTER WHERE A, COUNT(*) FILTER WHERE B. Q18 BIT_AND / BIT_OR - when does bit-aggregation matter (flags). Q19 BOOL_AND / BOOL_OR - used for "all-or-any" group checks. Q20 HAVING with subquery - can it reference outer GROUP BY columns? Q21 Why does GROUP BY GROUPING SETS((a), (b)) produce 2 reports in one query? Q22 Explain DISTINCT ON inside aggregation contexts. Q23 What does AVG(NULL, NULL, 5) return in Postgres? (Skips NULLs.) Q24 Why does SUM() on an empty set return NULL but COUNT() return 0? Q25 ORDER BY inside aggregate (ARRAY_AGG col ORDER BY ...) - execution model. PERCENTILES & STATISTICAL AGGREGATES Q26 Median order net_total. Q27 P90 order net_total. Q28 P99 order net_total. Q29 Median, P90, P99 in one row. Q30 Median resolution_time per ticket priority. Q31 Median time-to-deliver per courier. Q32 P95 call_duration per call_reason. Q33 P99 page_view dwell time per device_type. Q34 Median product price per brand. Q35 Median pay_slip gross_salary per dept. Q36 STDDEV salary per dept. Q37 STDDEV ad spend per platform. Q38 VARIANCE order net_total per status. Q39 MIN, MAX, AVG, MEDIAN per store. Q40 Quartiles (P25, P50, P75) of order_total per region. Q41 MODE() WITHIN GROUP - most-frequent order_status. Q42 MODE() WITHIN GROUP - most-frequent city per tier. Q43 PERCENT_RANK preview: identify orders in top 10% by net_total. Q44 CUME_DIST preview: cumulative distribution of order_total. Q45 Range (MAX - MIN) of order_total per region. Q46 Coefficient of variation = STDDEV / AVG. Q47 Skewness check: AVG vs MEDIAN per category (proxy: comparing means). Q48 P95 vs MAX delivery_days - outlier detection. Q49 Median revenue per fiscal quarter. Q50 PERCENTILE_DISC vs PERCENTILE_CONT comparison on the same set. GROUPING SETS / CUBE / ROLLUP Q51 ROLLUP(region, status): per-region+status counts + per-region subtotal + grand total. Q52 CUBE(device_type, os): all 2^2 subtotal combinations. Q53 GROUPING SETS((priority), (status)): two reports in one query. Q54 ROLLUP(year, month) for monthly revenue + yearly subtotals + grand total. Q55 CUBE(brand_id, category_id): full cross-tabulation of brand x category. Q56 GROUPING SETS((cust_tier, region), (cust_tier), ()): hierarchical revenue report. Q57 ROLLUP(dept, role) for employee counts + dept subtotals + grand total. Q58 Use GROUPING(col) to label subtotal rows clearly. Q59 Filter only subtotal rows: WHERE GROUPING(col) = 1. Q60 ROLLUP(region, store): regional + store-level summaries. Q61 CUBE(payment_method, status): all combinations of payment+status counts. Q62 GROUPING SETS for marketing dashboard: campaign-level + platform-level + grand total. Q63 ROLLUP(supplier, product): supplier-level + product-level inventory totals. Q64 ROLLUP(year, quarter) - fiscal report. Q65 CUBE(brand, region, category): 3-dim subtotals. Q66 GROUPING SETS with empty (): include grand-total row. Q67 ORDER BY with GROUPING() puts subtotals at the bottom. Q68 ROLLUP-based "P&L hierarchy" report: cat -> subcat -> grand. Q69 CUBE-based "matrix" report: row=region, col=channel. Q70 GROUPING SETS to merge "by tier" and "by year" in one result. Q71 Replace 3 UNION ALL queries with 1 GROUPING SETS query. Q72 Show GROUPING IDs (binary) for each row in a CUBE. Q73 Top-N within each grouping level (combine ROLLUP + windows preview). Q74 Conditional subtotal label using CASE + GROUPING(). Q75 Per region per quarter, count orders + subtotal per region + grand total. ARRAY/STRING/JSON_AGG + custom aggregates Q76 Per category, ARRAY_AGG(product_name) - list every product. Q77 Per region, ARRAY_AGG(store_name ORDER BY store_name). Q78 Per customer, ARRAY_AGG(order_id ORDER BY order_date DESC). Q79 Per dept, STRING_AGG(employee_name, ', ' ORDER BY hire_date). Q80 Per priority, STRING_AGG(ticket_subject, ' | ' ORDER BY created_date DESC) LIMIT-style. Q81 Per courier, JSON_AGG(JSON_BUILD_OBJECT('shipment_id', s, 'date', d)). Q82 Per campaign, JSONB_OBJECT_AGG(platform, total_spend). Q83 Per customer, JSON_AGG(orders) returning a JSON array. Q84 Per category, ARRAY_AGG(DISTINCT brand_name). Q85 Per agent, JSONB_AGG(JSON_BUILD_OBJECT('ticket', id, 'status', status)). Q86 Per store, ARRAY_AGG(role) FILTER WHERE active. Q87 Per session, ARRAY_AGG(url ORDER BY view_time) - clickstream. Q88 Per warehouse, ARRAY_AGG(product_id) FILTER WHERE quantity_on_hand < 10. Q89 Per call_reason, STRING_AGG(transcript_summary, ' --- ' ORDER BY call_date DESC). Q90 Per tier, ARRAY_AGG(member_email). Q91 BIT_OR(flags) - combine bit flags per group. Q92 BOOL_OR(is_premium) - does this group have any premium customer. Q93 BOOL_AND(is_compliant) - group fully compliant flag. Q94 Custom percent: SUM(CASE WHEN x THEN 1 ELSE 0 END) * 100.0 / COUNT(*) per group. Q95 Custom running total via CASE-CUM inside ARRAY_AGG (preview). Q96 Build a hash of group via md5(STRING_AGG(col, ',' ORDER BY col)). Q97 Build a "set diff" using two ARRAY_AGGs and array operators. Q98 ARRAY_AGG combined with WITH ORDINALITY: preserve original order. Q99 JSON_AGG to build a nested structure for an API response. Q100 Per customer, JSONB_BUILD_OBJECT('orders', JSON_AGG(...), 'reviews', JSON_AGG(...)) - full customer card. Production scenarios, optimisation
OLAP CUBES Q1 CUBE(region, month, status) - full 3D. Q2 ROLLUP(year, quarter, month) - hierarchical. Q3 GROUPING SETS for parallel cohort views. Q4 Per region x month x status, revenue + subtotals. Q5 Per brand x category x region, revenue. Q6 Per tier x age_band x city, count. Q7 Per priority x dept x month, ticket count. Q8 Per supplier x warehouse x month, shipment count. Q9 Per platform x campaign x month, ad spend. Q10 Per device x os x browser, page view count. Q11 Per category x brand x supplier x region, sales. Q12 Use GROUPING() to label rows. Q13 Filter only subtotal rows. Q14 Filter only grand total. Q15 Cubes with multiple measures (SUM + AVG + COUNT). Q16 Cubes with FILTER per measure. Q17 Per region x month x status as a cross-tab. Q18 Year-over-year cube. Q19 Quarter-over-quarter cube. Q20 Day-of-week x hour-of-day cube. Q21 Customer cohort x month x tier cube. Q22 Ad attribution cube: campaign x source x medium x geo. Q23 Fiscal cube: fiscal year x quarter x dept. Q24 Combine ROLLUP with FILTER (per-status totals). Q25 Build executive cube: 6 dimensions x 4 measures. DISTRIBUTIONS & STATISTICS Q26 Distribution of net_total: 20-bucket histogram. Q27 Distribution of order_date: monthly bucket. Q28 Distribution of ticket priority. Q29 Distribution of page_views per session. Q30 Customer LTV distribution. Q31 Time-to-deliver distribution. Q32 Time-to-resolve distribution. Q33 Refund-rate distribution per product. Q34 Review-length distribution. Q35 Median + MAD (median absolute deviation). Q36 Mean / median / mode together. Q37 Skewness: (mean - median) / stddev. Q38 Z-score of each order vs population. Q39 Outlier detection: z > 3. Q40 IQR outlier detection (1.5 x IQR). Q41 Pearson correlation (price vs rating). Q42 Spearman correlation (preview). Q43 Covariance between two metrics. Q44 Linear regression slope (REGR_SLOPE). Q45 R^2 (REGR_R2). Q46 Moving average (preview window). Q47 Exponentially weighted moving average. Q48 Anomaly detection via 7-day SMA vs current. Q49 Seasonality detection (week-over-week diff). Q50 P-value for difference of means (manual computation). PIVOTS & UNPIVOTS Q51 Pivot orders by month: rows = year, columns = month. Q52 Pivot tickets by status: rows = priority, columns = status. Q53 Pivot revenue by region x tier. Q54 Pivot reviews by rating: rows = brand, columns = rating. Q55 Pivot inventory by warehouse x product. Q56 Pivot pay_slips by year x dept. Q57 Pivot calls by reason x shift. Q58 Pivot campaigns by platform x month. Q59 Unpivot order_items metrics. Q60 Unpivot per-customer scoring. Q61 Crosstab with N dynamic columns (tablefunc extension). Q62 Pivot using FILTER for each column. Q63 Pivot using CASE for each column. Q64 Pivot using ARRAY_AGG. Q65 Pivot using jsonb_object_agg. Q66 Pivot with percentage of total per row. Q67 Pivot with running total. Q68 Pivot with rank within row. Q69 Reverse pivot via UNION ALL. Q70 Reverse pivot via jsonb_each. Q71 Stacked column report. Q72 Sparse vs dense pivot. Q73 Pivot with nulls treated as 0. Q74 Multi-measure pivot. Q75 Pivot with comparison vs prior period. FUNNELS & ANOMALIES Q76 Funnel: visit -> signup -> first order. Q77 Funnel: signup -> activation -> retention -> revenue. Q78 Funnel: campaign click -> cart -> checkout -> paid. Q79 Funnel conversion %. Q80 Funnel drop-off per step. Q81 Time-between-step funnel. Q82 Cohort funnel by signup month. Q83 Multi-touch attribution. Q84 First-touch attribution. Q85 Last-touch attribution. Q86 Linear-touch attribution. Q87 Time-decay attribution. Q88 Anomaly: revenue today vs 30-day avg. Q89 Anomaly: ticket count today vs 30-day avg. Q90 Anomaly: error log spike. Q91 Anomaly: SLA breach rate. Q92 Anomaly: per-product return rate. Q93 Anomaly: customer behavior drift. Q94 Outlier orders. Q95 Outlier returns. Q96 Detect bot traffic. Q97 Detect data quality issues (sudden NULLs). Q98 Detect schema drift. Q99 Detect "stuck" inventory (not moving). Q100 Build a "RetailMart anomaly summary" - 20 detectors.