Window Functions and Running Calculations · seed 1 · A4, ink-friendly. The answer key prints on its own page for grown-ups.

Totals that keep every row

Computing · Data & Databases · ages 19-20
Name ______________________   Date ____________
  1. What does PARTITION BY do?

    • Deletes duplicate rows
    • Restarts the math per group
    • Sorts the whole table forever
  2. What survives a window function?

    • Every detail row
    • Only one row per group
    • Only the column names
  3. GROUP BY keeps every detail row in the output.

    Circle one:   True   False

  4. Two orders tie for second. Which rank form leaves a gap?

    • ROW_NUMBER
    • DENSE_RANK
    • RANK
  5. Which query shows each order beside its customer running total?

    • SELECT customer, date, amount, SUM(amount) OVER (PARTITION BY customer ORDER BY date) FROM Orders
    • SELECT customer, SUM(amount) FROM Orders GROUP BY customer
    • SELECT DISTINCT customer FROM Orders
  6. Why can GROUP BY not give the same output as the running total?

    • It runs too fast
    • It collapses the rows the totals sit beside
    • It forbids all sums
  7. A self join is always clearer than a window for running totals.

    Circle one:   True   False

  8. A report needs ties sharing rank 2 with no rank skipped. Which form?

    • RANK
    • ROW_NUMBER
    • DENSE_RANK
LightMySky · lightmysky.comW1-mt_aaVxFPjWQv-s1

Answer key

For grown-ups. Fold this page away before handing over the rest.

Totals that keep every row W1-mt_aaVxFPjWQv-s1

  1. Restarts the math per group · Each partition gets a fresh calculation.
  2. Every detail row · Windows calculate without collapsing rows.
  3. False · Grouping collapses each group to one row.
  4. RANK · RANK shares a rank then skips the next.
  5. SELECT customer, date, amount, SUM(amount) OVER (PARTITION BY customer ORDER BY date) FROM Orders · Only the window keeps rows beside totals.
  6. It collapses the rows the totals sit beside · Collapsed rows cannot carry per-row totals.
  7. False · The window states partition and order in one pass.
  8. DENSE_RANK · DENSE_RANK shares ranks and packs tight.
Worksheet · LightMySky