Reproduce this SQL in Python:
Days within a user are unique ISO dates. change is None for a user's first day. Return the rows
with the extra columns.
Implement windowed. Input: rows: list[dict] with user, day, amount. Returns: list[dict].
def windowed(rows: list[dict]) -> list[dict]:
return sorted(rows, key=lambda r: (r["user"], r["day"]))
Run executes the public tests. Submit grades against public and hidden tests.
Reproduce this SQL in Python:
SELECT user, day, amount,
SUM(amount) OVER (PARTITION BY user ORDER BY day) AS running_total,
DENSE_RANK() OVER (PARTITION BY user ORDER BY amount DESC) AS amount_rank,
amount - LAG(amount) OVER (PARTITION BY user ORDER BY day) AS change
FROM orders ORDER BY user, dayDays within a user are unique ISO dates. change is None for a user's first day. Return the rows
with the extra columns.
Implement windowed. Input: rows: list[dict] with user, day, amount. Returns: list[dict].
def windowed(rows: list[dict]) -> list[dict]:
return sorted(rows, key=lambda r: (r["user"], r["day"]))
Run executes the public tests. Submit grades against public and hidden tests.