Total Sales per Region using CTEs

SQL coding challenge · Difficulty: easy · +50 XP

A retail company wants to analyze its sales performance across different regions. Given a 'sales' table, calculate the total sales amount for each region. Use a Common Table Expression (CTE) to simplify the query. Return region and total_sales, ordered by total_sales descending.

Example input

`

sales table:

sale_id | region | amount

1 | North | 1200.00

2 | South | 850.50

3 | East | 640.30

4 | West | 960.00

5 | North | 760.75

6 | South | 1120.00

7 | East | 950.50

`

Expected output

`

region | total_sales

South | 1970.50

North | 1960.75

East | 1590.80

West | 960.00

`

Solve this challenge on PySpark.in