Skip to content

Commit 8f59ff6

Browse files
committed
DataCamp - Submit "Data manipulation in Snowflake" - 2 - Finding the most efficient composer.
1 parent e0bc429 commit 8f59ff6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

datacamp/data_manipulation_in_snowflake.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,25 @@ ORDER BY avg_track_length DESC;
204204
```
205205

206206
## Finding the most efficient composer
207-
```
207+
```sql
208+
-- Create a CTE called track_metrics, convert milliseconds to seconds
209+
WITH track_metrics AS (
210+
SELECT
211+
composer,
212+
milliseconds / 1000 AS num_seconds,
213+
unit_price
214+
FROM store.track
215+
-- Retrieve records where composer is not NULL
216+
WHERE composer IS NOT NULL
217+
)
208218

219+
SELECT
220+
composer,
221+
-- Find the average price-per-second
222+
AVG(unit_price / num_seconds) AS cost_per_second
223+
FROM track_metrics
224+
GROUP BY composer
225+
ORDER BY cost_per_second DESC;
209226
```
210227

211228
## Where are customers buying?

0 commit comments

Comments
 (0)