DataLane

19. Payment method mix by day

mediumProNot started~12 minPivotAggregation

Asked in screens shaped like: Stripe, PayPal, Adyen

Turn payment methods from rows into columns so each day is a single row with card, ach, and wallet totals. Warehouses have a PIVOT clause; plain SQL does it with conditional aggregation.

Requirements

  • Columns: paid_day, card, ach, wallet
  • paid_day is the date part of paid_at
  • Each method column sums that method’s amount for the day, 0 when absent
  • All money columns rounded to 2 decimals, ordered by paid_day

Expected output

paid_day, card, ach, wallet

Row order is graded, so ORDER BY matters here.

SQL editor

Loading SQL engine…

Ctrl/Cmd + Enter submits

Run your query to see the result set.

Pro problem

Medium problems unlock with Pro

Easy pads stay free. Medium and hard SQL and Python problems — editor, tests, hints, and solutions — open after you upgrade to Pro or coaching.

See plansPractice free easy problems
↑↓ navigate openesc close