Compare Each Order to the First (FIRST_VALUE)

medium
Unit 13 · Window Functions VI0/2 to milestone

For every order, show how it compares with the customer's first order. Return id, name, total, first_total (the total of that customer's first order) and pct_vs_first (the percentage change from the first order, rounded to 1 decimal place). A customer's orders are ordered by order_date, then id. Sort the output by name, then order_date, then id.

Schema

customers(id, name, country, signup_date)
orders(id, customer_id, order_date, total)
#window-functions#first-value1 visible + 1 hidden tests
query.sql · SQLite
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Compare Each Order to the First (FIRST_VALUE) · TechGradify