SUM OVER: Show Grand Total on Every Row

SQL coding challenge · Difficulty: easy · +50 XP

Problem

Every row in the report needs the grand total of all sales embedded in it — the same number on every row. Useful for calculating each sale's percentage contribution.

Tables

Table: daily_sales

| sale_id | day_name | amount |
| 1 | Mon | 100 |
| 2 | Tue | 200 |
| 3 | Wed | 300 |
| 4 | Thu | 400 |
| 5 | Fri | 500 |

Expected Output

| sale_id | day_name | amount | grand_total |
| 1 | Mon | 100 | 1500 |
| 2 | Tue | 200 | 1500 |
| 3 | Wed | 300 | 1500 |
| 4 | Thu | 400 | 1500 |
| 5 | Fri | 500 | 1500 |
  • Return: sale_id, day_name, amount, grand_total
  • Same value on every row — no ORDER BY inside OVER()
  • Sort by sale_id ascending
  • Function: SUM(amount) OVER () — empty OVER means entire table

Solve this challenge on PySpark.in