Challenge: Calculate Running Totals
Swipe to start coding
Write a SQL query to calculate the running total of expenses over time, using the transactions table. Only include rows where the category is 'Expense'. The results must be ordered by transaction_date. For each row, return the transaction_date, amount, description, and a column named running_total that is the sum of all amount values for expenses from the earliest to the current row (inclusive), ordered by date.
- Filter the
transactionstable to include only rows wherecategoryis'Expense'. - Select the
transaction_date,amount, anddescriptioncolumns. - Calculate a running total of
amountfor each row, ordered bytransaction_date, and include it asrunning_total. - Order the results by
transaction_date.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 4.55
Challenge: Calculate Running Totals
Swipe to show menu
Swipe to start coding
Write a SQL query to calculate the running total of expenses over time, using the transactions table. Only include rows where the category is 'Expense'. The results must be ordered by transaction_date. For each row, return the transaction_date, amount, description, and a column named running_total that is the sum of all amount values for expenses from the earliest to the current row (inclusive), ordered by date.
- Filter the
transactionstable to include only rows wherecategoryis'Expense'. - Select the
transaction_date,amount, anddescriptioncolumns. - Calculate a running total of
amountfor each row, ordered bytransaction_date, and include it asrunning_total. - Order the results by
transaction_date.
Solution
Thanks for your feedback!
single