0
0
SQLquery~10 mins

Running total without window functions in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select all sales amounts from the sales table.

SQL
SELECT [1] FROM sales;
Drag options to blanks, or click blank then click option'
Aprice
Btotal
Camount
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting a column name that does not exist in the table.
Using a keyword instead of a column name.
2fill in blank
medium

Complete the code to calculate the running total of sales amounts using a correlated subquery.

SQL
SELECT s1.id, s1.amount, (SELECT SUM(s2.amount) FROM sales s2 WHERE s2.id <= [1]) AS running_total FROM sales s1 ORDER BY s1.id;
Drag options to blanks, or click blank then click option'
As1.id
Bs2.id
Cs2.amount
Ds1.amount
Attempts:
3 left
💡 Hint
Common Mistakes
Using the inner query alias s2.id instead of the outer s1.id.
Comparing the wrong columns in the WHERE clause.
3fill in blank
hard

Fix the error in the code to correctly calculate the running total without window functions.

SQL
SELECT id, amount, (SELECT SUM(amount) FROM sales WHERE id [1] id) AS running_total FROM sales ORDER BY id;
Drag options to blanks, or click blank then click option'
A>
B>=
C=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using = which sums only the current row.
Using > which sums rows after the current one.
4fill in blank
hard

Fill both blanks to create a running total query that sums amounts up to the current row id.

SQL
SELECT s1.id, s1.amount, (SELECT SUM([1]) FROM sales s2 WHERE s2.id [2] s1.id) AS running_total FROM sales s1 ORDER BY s1.id;
Drag options to blanks, or click blank then click option'
Aamount
B<=
C>=
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name in the sum.
Using the wrong comparison operator.
5fill in blank
hard

Fill all three blanks to write a running total query without window functions, using aliases and correct comparison.

SQL
SELECT [1], [2], (SELECT SUM([3]) FROM sales s2 WHERE s2.id <= s1.id) AS running_total FROM sales s1 ORDER BY s1.id;
Drag options to blanks, or click blank then click option'
As1.id
Bs1.amount
Camount
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using columns without the correct alias.
Using the wrong column name in the sum.