Window Functions 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
CONCEPTUAL Q1 What does a window function do that GROUP BY does not? Q2 Explain the OVER() clause - what does an empty OVER() mean? Q3 What does PARTITION BY do inside OVER()? Q4 What does ORDER BY inside OVER() control for ranking functions? Q5 Define ROW_NUMBER() - is it ever tied? Q6 Define RANK() - what happens to the number after a tie? Q7 Define DENSE_RANK() - how does it differ from RANK() after ties? Q8 Give a one-line summary of ROW_NUMBER vs RANK vs DENSE_RANK on tied values. Q9 What does NTILE(4) do? Q10 Why must a ranking window function have an ORDER BY inside OVER()? Q11 Can you use a window function in a WHERE clause directly? Why not? Q12 What is the usual workaround to filter on a window result (e.g. rn = 1)? Q13 Do window functions remove rows like GROUP BY does? Q14 What is a "partition" vs a "group" conceptually? Q15 After ROW_NUMBER() OVER (ORDER BY x), what is the first row's number? Q16 How do NULLs in the window ORDER BY sort by default (ASC)? Q17 What does PARTITION BY region, category mean (two-level partition)? Q18 Is ROW_NUMBER deterministic when the ORDER BY has ties? How to fix? Q19 What is the "Top-N per group" pattern in one sentence? Q20 Why is ROW_NUMBER preferred over RANK for deduplication? Q21 What does NTILE return when rows don't divide evenly into buckets? Q22 Can the same query have two window functions with different OVER() clauses? Q23 Conceptually, in what order does a window function run vs WHERE and GROUP BY? Q24 What's the difference between RANK() and ROW_NUMBER() output ranges? Q25 Name one analyst use-case each for ROW_NUMBER, RANK, and NTILE. ROW_NUMBER Q26 Number all orders by order_date (newest first) with ROW_NUMBER. Q27 Number products by price descending. Q28 Number customers by registration_date ascending. Q29 Assign a row number to employees ordered by salary descending. Q30 Number orders within each customer by order_date (PARTITION BY cust_id). Q31 Number products within each brand by price descending. Q32 Number reviews within each product by review_date descending. Q33 Number employees within each store by salary descending. Q34 Get the single most recent order per customer (rn = 1 pattern). Q35 Get the cheapest product per brand (ROW_NUMBER, rn = 1). Q36 Get the latest review per customer. Q37 Number tickets within each priority by created_date. Q38 Number stores within each region by square_ft descending. Q39 Number calls within each customer by call_start_time. Q40 Add a global row number to a SELECT of the 50 highest-value orders. Q41 Number payments within each order by payment_date. Q42 Number shipments within each courier by shipped_date. Q43 Get the first (earliest) order per store using ROW_NUMBER. Q44 Number addresses within each customer (is_default first). Q45 Number ads_spend rows within each platform by amount descending. Q46 Use ROW_NUMBER to label "1st, 2nd, 3rd..." purchase per customer. Q47 Number products within each supplier by product_name. Q48 Get the highest-paid employee per department (rn = 1). Q49 Number orders per store by net_total descending. Q50 Deduplicate customers by email, numbering duplicates by registration_date desc. RANK / DENSE_RANK Q51 RANK products by price descending (whole table). Q52 DENSE_RANK products by price descending; compare to Q51's gaps. Q53 RANK employees by salary within each department. Q54 DENSE_RANK orders by net_total within each customer. Q55 RANK stores by total square_ft within each region. Q56 Show ROW_NUMBER, RANK, and DENSE_RANK side by side for products by price. Q57 RANK customers by tier then registration_date. Q58 DENSE_RANK products within each brand by price. Q59 RANK reviews by rating within each product (ties expected). Q60 Find the rank of a specific product's price among all products. Q61 RANK ticket priorities by created_date within each status. Q62 DENSE_RANK employees by salary (whole company) - count distinct salary levels. Q63 RANK orders by order_date within each store. Q64 DENSE_RANK brands by number of products (rank a pre-aggregated set). Q65 RANK calls by duration within each agent. Q66 Show why RANK skips numbers after a tie using rating data. Q67 RANK products by cost_price within each category (via brand->category). Q68 DENSE_RANK customers by points_balance (loyalty.members). Q69 RANK shipments by delivery time (delivered_date - shipped_date) within courier. Q70 RANK pay_slips by net_salary within each salary_year. Q71 Find products tied at the same RANK by price within a brand. Q72 DENSE_RANK order statuses by frequency. Q73 RANK regions by store count. Q74 RANK employees by salary descending and keep only rank <= 3 per department. Q75 Compare RANK vs DENSE_RANK on customer tiers (lots of ties). NTILE & TOP-N Q76 NTILE(4) to split products into 4 price quartiles. Q77 NTILE(10) to split customers into spend deciles (join orders). Q78 NTILE(3) to split employees into low/mid/high salary bands. Q79 Label NTILE(4) buckets as Q1..Q4 with a CASE. Q80 NTILE(5) on order net_total; show the boundary values per bucket. Q81 Top-3 highest-paid employees per department (ROW_NUMBER <= 3). Q82 Top-3 products by price per brand. Q83 Top-2 most recent orders per customer. Q84 Top-5 stores by revenue per region (rank pre-aggregated revenue). Q85 Bottom-3 products by price per brand (ascending rank). Q86 NTILE(4) of customers by registration_date (signup cohorts by quartile). Q87 Second-highest-priced product overall (rn = 2). Q88 Second-highest salary per department. Q89 NTILE(100) to approximate percentile rank of order values. Q90 Top-1 review (highest rating, latest) per product. Q91 NTILE(4) of products by cost_price within each brand. Q92 Top-3 longest calls per agent. Q93 Top-N with a deterministic tie-break (ROW_NUMBER vs RANK choice). Q94 NTILE(2) to split orders into "above/below median" halves. Q95 Top-10 customers by points_balance, numbered. Q96 Bucket stores into 4 size tiers with NTILE on square_ft. Q97 Top-3 brands by product count. Q98 NTILE(4) of employees by salary within each store. Q99 Keep only the 3rd-ranked product by price per brand (exactly nth). Q100 Build spend quartile labels per customer (NTILE(4) + CASE) - RFM preview. Combined ideas, multi-step thinking
CONCEPTUAL Q1 Why can't you reference a window alias in the same SELECT's WHERE? Show the subquery/CTE fix. Q2 How does PARTITION BY a, b differ from PARTITION BY a for ranking? Q3 Why does ROW_NUMBER need a tie-breaker column to be reproducible? Q4 Explain how RANK leaves gaps and DENSE_RANK does not, with a tie example. Q5 When ranking, what does ORDER BY ... DESC NULLS LAST change vs default? Q6 NTILE(4) vs width_bucket - when would an analyst pick each? Q7 Why is "Top-N per group" a window job, not a GROUP BY job? Q8 How do you get exactly the Nth row per group (not top-N)? Q9 Dedup: why ORDER BY in the window decides which duplicate you keep. Q10 Can two window functions share a window via the WINDOW clause? Show the idea. Q11 What happens to NTILE buckets when group size < bucket count? Q12 Why might RANK and ROW_NUMBER give the same result on a UNIQUE column? Q13 Explain "PARTITION BY with no ORDER BY" for a ranking function. Q14 How do you rank descending but break ties by an ascending second key? Q15 Why does filtering rn <= 3 in an outer query implement top-3? Q16 What's the cost difference between ranking all rows vs adding a WHERE first? Q17 How does DISTINCT interact with a window function in the SELECT? Q18 Why is NTILE sensitive to the ORDER BY tie order? Q19 Explain quartile labeling (NTILE(4) -> Q1..Q4) for segmentation. Q20 When is RANK the "right" choice over ROW_NUMBER for business meaning? Q21 How do you rank within a partition but reset for each new partition value? Q22 Why might you PARTITION BY a derived expression (e.g. DATE_TRUNC)? Q23 What does PERCENT_RANK conceptually add over RANK? (preview only) Q24 How do you keep ties together at the top-N boundary (RANK <= N vs ROW_NUMBER <= N)? Q25 Why compute ranking in a CTE before joining to other tables? RANKING WITHIN PARTITIONS Q26 Rank products by price within each brand, tie-break by product_id. Q27 Rank employees by salary within each store, tie-break by joining_date. Q28 Rank orders by net_total within each store and order_date month. Q29 Rank customers by points_balance within each tier (join loyalty.members). Q30 Rank products by price within each category (products -> brand -> category). Q31 Rank stores by total revenue within each region (CTE-aggregate then rank). Q32 Rank reviews by rating then review_date within each product. Q33 Rank employees by salary within each (store, role). Q34 Rank brands by product count within each category. Q35 Rank agents by resolved-ticket count within each ticket category. Q36 Rank orders within each customer by net_total DESC, order_date DESC. Q37 DENSE_RANK products by cost_price within each supplier. Q38 Rank shipments by delivery-day count within each courier. Q39 Rank pay_slips by net_salary within each (salary_year, salary_month). Q40 Rank customers by order count within each registration-year cohort. Q41 Rank products by review count within each brand (join reviews). Q42 Rank warehouses by total snapshot quantity within each region. Q43 Rank stores by employee count within each region. Q44 Rank order_items by net_amount within each order. Q45 Rank campaigns by total ad spend within each platform (join ads_spend). Q46 Rank customers by lifetime spend within each city (via addresses). Q47 Rank products by units sold within each brand (join order_items). Q48 Rank employees by salary within department; keep ranks 1-5. Q49 Rank tickets by resolution time within each agent. Q50 Rank regions by average order value (aggregate then rank). TOP-N / NTH PER GROUP Q51 Top-3 highest-paid employees per department (with names). Q52 Top-3 best-selling products per brand by units. Q53 Top-2 most recent orders per customer (full rows). Q54 Top-5 stores by revenue per region. Q55 The 2nd-highest salary per department (exactly nth). Q56 The 3rd-most-recent order per customer. Q57 Top-1 (latest) review per product, with the review text. Q58 Top-3 customers by spend per city. Q59 Top-N with tie inclusion: all products tied for the top price per brand (RANK). Q60 The single highest-value order per store. Q61 Top-3 longest-open tickets per agent. Q62 Top-2 products by margin (price - cost_price) per category. Q63 The earliest (first-ever) order per customer. Q64 Top-3 regions by store count (rank aggregated). Q65 Top-5 most-reviewed products per brand. Q66 The most expensive product per supplier. Q67 Top-3 agents by call volume per call_reason. Q68 Top-2 highest-rated reviews per customer. Q69 The nth order (parametric, e.g. 5th) per customer. Q70 Top-3 warehouses by capacity per region. Q71 Top-1 per group but break ties deterministically (ROW_NUMBER design). Q72 Top-10 orders overall, then number them per store. Q73 Top-3 brands by revenue per category. Q74 The most recent payment per order. Q75 Top-3 customers by review count per registration year. NTILE BUCKETING & DEDUP Q76 NTILE(4) customers into spend quartiles (join orders, aggregate). Q77 NTILE(10) products into price deciles within each brand. Q78 NTILE(5) orders into net_total quintiles per store. Q79 NTILE(4) employees into salary quartiles per department; label Q1..Q4. Q80 NTILE(3) stores into small/mid/large by square_ft per region. Q81 Dedup customers by email keeping the most recently registered. Q82 Dedup products by product_name (lowercased) keeping the cheapest. Q83 Dedup orders by (cust_id, order_date) keeping the highest net_total. Q84 Dedup addresses keeping the default (is_default) per customer. Q85 NTILE(4) of review ratings per product into quartile buckets. Q86 NTILE(100) percentile bucket of order net_total per region. Q87 Bucket customers into RFM "Monetary" quartiles (NTILE(4) on spend). Q88 Bucket customers into "Frequency" quartiles (NTILE(4) on order count). Q89 Dedup reviews keeping the latest per (customer, product). Q90 NTILE(4) of products by units sold within category. Q91 Dedup near-duplicate suppliers by lowercased trimmed name. Q92 NTILE(5) of employees by salary across the company; show band ranges. Q93 Dedup payments keeping the latest per order. Q94 NTILE(4) of stores by revenue; tag the top quartile. Q95 Dedup customers by phone (digits only) keeping the latest. Q96 NTILE(3) tenure buckets of employees by joining_date per department. Q97 Combine: top quartile (NTILE(4)=1) customers by spend, then rank within it. Q98 Dedup order_items keeping the line with the largest net_amount per (order, product). Q99 NTILE(4) of products by margin per brand. Q100 RFM bucket preview: NTILE(4) on recency, frequency, monetary separately per customer. Interview grade, edge cases
CONCEPTUAL Q1 Top-N per group: compare RANK <= N vs ROW_NUMBER <= N when ties exist at the boundary. Q2 Why does ROW_NUMBER give exactly N rows but RANK may give more? Q3 Design a deterministic tie-break for "latest order per customer". Q4 Explain why a window function is evaluated after WHERE/GROUP BY/HAVING but before ORDER BY/LIMIT. Q5 Why must "filter on rank" go in an outer query or CTE (not WHERE)? Q6 Dedup: prove ORDER BY in the partition picks the surviving row. Q7 NTILE vs PERCENT_RANK vs CUME_DIST for "percentile" - which for RFM bucketing? Q8 When group size is not divisible by NTILE(n), which buckets get the extra rows? Q9 Why can ranking the full table then filtering be slower than a LATERAL top-N? Q10 Explain the leftmost-tie problem: equal keys + ROW_NUMBER = arbitrary winner. Q11 How do you compute "rank within group" and "rank overall" in one query? Q12 Why is DISTINCT + window function a common bug? Q13 How to get the top-N AND a count of how many were tied out? Q14 Why PARTITION BY DATE_TRUNC('month', d) for monthly top-N? Q15 Explain "exactly the 2nd highest" with ties (DENSE_RANK = 2). Q16 When should top-N per group be solved with DISTINCT ON instead? (preview) Q17 How does NULLS FIRST/LAST in the window ORDER BY change rank 1? Q18 Why does deduping on a non-unique ORDER BY risk dropping the wrong row? Q19 How to bucket into quartiles but keep bucket edges stable across refreshes? Q20 Explain percentile rank of a value via NTILE(100) and its limitations. Q21 Why might RANK over a huge partition need a supporting sort/index (Topic 20)? Q22 How to rank by a composite score computed in the same query? Q23 Top-N per group across two grain levels (region then store) - how? Q24 Why is "keep latest per email" the canonical dedup interview question? Q25 How to express "everyone in the top decile of spend" cleanly? TOP-N / NTH PER GROUP Q26 SCENARIO: The CHRO wants the top-3 earners per department with names and salary. Q27 Top-3 products by revenue (units x price) per brand. Q28 The 2nd-highest-salary employee per store (exactly nth, ties via DENSE_RANK). Q29 Top-5 customers by lifetime spend per region. Q30 The latest delivered order per customer (full row, deterministic). Q31 Top-3 most-returned products per category (join returns->order_items->products). Q32 The single highest-margin product per supplier. Q33 Top-3 agents by resolved tickets per ticket category. Q34 The 3rd order ever placed by each customer. Q35 Top-2 stores by revenue per region, with the region total alongside. Q36 Top-N including ties: all products at the max price per brand (RANK = 1). Q37 The most recent review per product, only where rating <= 2 (worst-recent). Q38 Top-3 highest-value orders per payment_mode. Q39 The earliest and latest order per customer in one result (two ROW_NUMBERs). Q40 Top-5 longest-duration calls per agent with caller info. Q41 The top product by units in each (brand, registration-year-of-buyer) - two-level. Q42 Top-3 customers by order count per acquisition month (registration cohort). Q43 The single cheapest in-stock product per warehouse (join snapshots). Q44 Top-3 campaigns by spend per platform with rank shown. Q45 The nth (parametric) most expensive product per category. Q46 Top-2 employees by salary per (store, role) tie-broken by tenure. Q47 The latest payment per order, only for Delivered orders. Q48 Top-3 regions by average order value (aggregate then rank). Q49 The highest-rated, then most-recent, review per product (multi-key order). Q50 Top-N per group then a grand ROW_NUMBER across the survivors. DEDUPLICATION & IDENTITY Q51 SCENARIO: DBA found duplicate emails - keep the most-recently-registered customer per email. Q52 List the rows that WOULD be deleted by Q51 (rn > 1). Q53 Dedup products by lowercased trimmed product_name, keep the cheapest. Q54 Dedup orders sharing (cust_id, order_date) - keep the highest net_total. Q55 Keep the default address per customer; if none, keep the lowest address_id. Q56 Dedup near-duplicate suppliers by lowercased name; keep the lowest supplier_id. Q57 Dedup reviews per (customer_id, product_id) keeping the latest review_date. Q58 Keep the latest payment per order; flag orders with multiple payments. Q59 Dedup customers by normalized phone (digits only) keeping latest registration. Q60 Identify products appearing under multiple brands (same name) and pick one canonical. Q61 Dedup order_items per (order_id, prod_id) keeping the max net_amount line. Q62 Find emails with >=3 duplicate accounts and rank the keepers. Q63 Keep the most recent snapshot per (warehouse_id, product_id). Q64 Dedup loyalty.members per customer (defensive) keeping highest points_balance. Q65 Produce a "golden record" per email: keep latest, list merged ids. Q66 Dedup tickets per (customer_id, subject) keeping the latest created_date. Q67 Keep the first-ever order per customer as their "acquisition order". Q68 Dedup addresses by (customer_id, pincode) keeping is_default then lowest id. Q69 Find customers whose duplicates span different cities (data-quality flag). Q70 Dedup products by (brand_id, product_name) keeping the most expensive. Q71 Rank duplicate-group sizes: which email has the most duplicate accounts? Q72 Keep the latest review per product and compute its position vs all reviews. Q73 Dedup calls per (customer_id, call_start_time::date) keeping the longest. Q74 Produce a deduped customer list (rn = 1) ready for an export. Q75 Validate dedup: count rows before vs after (rn = 1) per email. NTILE SEGMENTATION & PERCENTILES Q76 SCENARIO: Marketing wants customers split into spend quartiles (NTILE(4)) labeled Q1..Q4. Q77 NTILE(10) spend deciles per region; show decile boundaries. Q78 RFM "Monetary": NTILE(5) on lifetime spend per customer. Q79 RFM "Frequency": NTILE(5) on order count per customer. Q80 RFM "Recency": NTILE(5) on days-since-last-order per customer. Q81 Combine the three NTILE(5) scores into an RFM code (e.g. '5-4-3'). Q82 Tag the top spend quartile customers as 'VIP' and rank within it. Q83 NTILE(4) products by margin per category; list the top-quartile products. Q84 Percentile rank of each order's net_total via NTILE(100) per region. Q85 NTILE(4) employees by salary per department; compare to company-wide quartile. Q86 Bucket stores into 4 revenue tiers; show count and avg per tier. Q87 NTILE(3) of products by units sold (slow/medium/fast movers) per brand. Q88 NTILE(4) of reviews by rating per product and tag the bottom quartile. Q89 Find customers in the top decile of BOTH frequency and monetary. Q90 NTILE(5) of warehouses by total stock; flag the lowest quintile for audit. Q91 Quartile of delivery time per courier (NTILE(4)); slowest quartile per courier. Q92 NTILE(4) of campaigns by spend per platform; top-quartile spenders. Q93 Build a "spend tier x frequency tier" segmentation grid (two NTILEs). Q94 NTILE(10) of order values overall; the 90th-percentile bucket threshold. Q95 Segment customers into quartiles and rank them within each quartile by recency. Q96 NTILE(4) tenure buckets of employees per store; newest-quartile list. Q97 Percentile bucket of product price per brand (NTILE(100)) and its rank. Q98 NTILE(4) of customers by review count; engaged top-quartile. Q99 Compare NTILE(4) bucket vs RANK-based quartile on the same column - when they differ. Q100 Full RFM segmentation: NTILE(5) R/F/M, map codes to Champions/Loyal/At-Risk/Lost. Production scenarios, optimisation
CONCEPTUAL Q1 Design a stable, reproducible ranking key for paginated leaderboards. Q2 Multiple OVER() clauses in one SELECT - cost model and the WINDOW clause to share them. Q3 Prove that ROW_NUMBER over a tie is non-deterministic without a unique tail key. Q4 Top-N per group: window-filter vs LATERAL vs DISTINCT ON - tradeoffs at scale. Q5 How ties + NTILE interact: why two equal values can land in different buckets. Q6 Why "rank then join" beats "join then rank" for fan-out control. Q7 Compose RANK over a weighted score (e.g. 0.5*norm_spend + 0.3*freq + 0.2*recency). Q8 Percentile semantics: NTILE(100) vs PERCENT_RANK vs CUME_DIST - exact differences. Q9 Deduplication at scale: choosing the partition key + ORDER BY for a golden record. Q10 Why DISTINCT ON is sometimes faster than ROW_NUMBER=1 for latest-per-group. Q11 Ranking within rolling cohorts (PARTITION BY DATE_TRUNC) - pitfalls. Q12 How to guarantee top-N returns <= N even with ties (and when you want >= N). Q13 Multi-level top-N (top-2 stores per region AND top-3 products per store) in one pass. Q14 Why segmentation buckets should be recomputed, not stored, for fairness over time. Q15 Designing RFM with NTILE: edge cases (all-equal frequency, single-order customers). Q16 When ranking on a computed column, why materialize it in a CTE first. Q17 Determinism across runs: collation, NULLS ordering, and tie tails. Q18 How to rank but exclude outliers (trim top/bottom percentile) cleanly. Q19 Top-N per group with a global cap (e.g. <=3 per brand but <=50 overall). Q20 Why a leaderboard needs both DENSE_RANK (display) and ROW_NUMBER (pagination). Q21 NTILE drift: why bucket membership changes as data grows, and mitigation. Q22 Ranking with business tie-break rules encoded as a CASE sort key. Q23 How to compute "share of rank-1" (how dominant the leader is) per group. Q24 Reproducible quartile cut-points: store the NTILE boundaries as a snapshot. Q25 Why a single query with 4 windows can beat 4 self-joins (correctness + speed). MULTI-WINDOW RANKING Q26 SCENARIO: VP Sales wants each product's rank within its brand AND its rank overall, side by side. Q27 For each employee: salary rank in department, in store, and company-wide (3 windows). Q28 Rank customers by spend within region and within tier in one query. Q29 Composite score leaderboard: weight spend/frequency/recency, then RANK + ROW_NUMBER. Q30 Per product: RANK by price and DENSE_RANK by units, compared. Q31 Two-level top-N: top-2 regions by revenue, and within them top-3 stores. Q32 Per order: line-item rank by net_amount and the order's rank among the customer's orders. Q33 Rank stores by revenue and by order count; flag where the two ranks disagree. Q34 Per customer: rank their orders by value and tag the single largest with a flag. Q35 Use the WINDOW clause to share one PARTITION across ROW_NUMBER, RANK, DENSE_RANK. Q36 Rank brands by revenue within category and the category by revenue overall. Q37 Per agent: rank by tickets resolved and by avg resolution speed; combined score. Q38 Rank products within brand and mark those also in the global top-100 by units. Q39 Per region: rank stores by revenue and by review score; show both. Q40 Build a "dominance" metric: leader's value / 2nd place value per group. Q41 Rank customers by recency and by monetary; keep those top-quartile in both. Q42 Per warehouse: rank products by stock and by turnover (join order_items). Q43 Rank pay_slips by net_salary within year and within (year, month). Q44 Multi-key tie-break encoded via CASE: priority then SLA then created_date. Q45 Per category: top product by units and top product by margin in one result. Q46 Rank campaigns by spend within platform and platform by spend overall. Q47 Per customer: position of their first order's value among all their orders. Q48 Rank cities by customer count and by total spend (via addresses + orders). Q49 Compute each product's percentile (NTILE 100) within brand and overall. Q50 A single query producing brand rank, category rank, and global rank for every product. DEDUP & TOP-N AT SCALE Q51 SCENARIO: Build a deduped "golden customer" table - one row per email, latest record, merged id list. Q52 Dedup at scale keeping latest per email; report total rows removed. Q53 Golden product record per lowercased name with surviving brand chosen by max units. Q54 Latest order per customer for 50k customers - compare ROW_NUMBER=1 vs DISTINCT ON. Q55 Top-3 products per brand across the full catalog, deterministic. Q56 Reconcile two near-duplicate supplier spellings into one canonical set. Q57 Dedup reviews keeping the highest-rated, then latest, per (customer, product). Q58 Top-N per group with a global cap of 100 survivors total. Q59 Find and rank the largest duplicate clusters (emails with most accounts). Q60 Golden address per customer (default -> latest -> lowest id) with audit trail. Q61 Top-5 customers by spend per city, only cities with >=100 customers. Q62 Latest snapshot per (warehouse, product) and rank products by that stock. Q63 Dedup order_items to one line per (order, product) keeping the max amount. Q64 Build the "first touch" order per customer and rank customers by its value. Q65 Top-3 per group but include ties at the boundary (RANK) and count the tie-outs. Q66 Dedup payments per order; for multi-payment orders, keep latest and sum the rest. Q67 Canonical product list: dedup by (brand, name), keep dearest, number duplicates. Q68 Top-N most-returned products per category with return-rate, deterministic. Q69 Identify customers whose duplicates differ in tier (data-integrity flag). Q70 Latest review per product and its rank among that product's ratings. Q71 Top-3 agents per category by resolved count, tie-broken by avg speed. Q72 Produce a deduped export (rn=1) and validate counts per partition. Q73 Top product per (brand, buyer-tier) - two-level, full catalog. Q74 Dedup customers by phone digits; resolve conflicting names by latest registration. Q75 Golden-record pipeline: rank, keep rn=1, collect merged ids via string_agg. SEGMENTATION SYSTEMS Q76 SCENARIO: Build a full RFM segmentation: NTILE(5) on Recency, Frequency, Monetary per customer. Q77 Map RFM codes to segments: Champions / Loyal / Potential / At-Risk / Lost. Q78 Customer spend deciles (NTILE(10)) with decile revenue contribution (Pareto check). Q79 Two-dimensional grid: spend quartile x frequency quartile, count per cell. Q80 Product ABC classification via NTILE on revenue contribution per category. Q81 Store performance quartiles per region with quartile averages. Q82 Percentile rank (NTILE 100) of every customer's spend; flag >= p95. Q83 RFM but robust to single-order customers (handle degenerate NTILE). Q84 Top-decile-by-spend AND top-decile-by-frequency overlap (the "best" cohort). Q85 Quartile of delivery time per courier; SLA-risk = bottom quartile. Q86 Employee comp quartiles per department vs company; flag underpaid top performers. Q87 Bucket products into fast/medium/slow movers (NTILE 3 on units) per brand. Q88 Segment campaigns into spend quartiles per platform; ROI-watch the top quartile. Q89 Customer "engagement quartile" from review+ticket+order counts (composite NTILE). Q90 Region revenue quartiles with each region's rank and quartile shown. Q91 Snapshot the NTILE(4) spend cut-points so buckets are reproducible next month. Q92 Cross-segment: which spend quartile dominates each city (mode per group). Q93 Decile migration setup: assign current spend decile per customer (for later compare). Q94 Flag "rising" customers: top frequency quartile but only mid monetary quartile. Q95 Product price-band segmentation (NTILE 5) per brand with band labels. Q96 Warehouse stock quintiles; lowest quintile flagged for replenishment review. Q97 Customer tier vs NTILE-spend-quartile mismatch (Gold tier but bottom spend quartile). Q98 Build an exec "leaderboard strip": top-3 per region with rank + dominance metric. Q99 RFM segment sizes and average monetary per segment (segmentation report). Q100 End-to-end: RFM-score every customer, label segments, and rank customers within each segment.