Question: Using FIRST_VALUE(), LAST_VALUE(), and NTH_VALUE()
Explore how to apply FIRST_VALUE LAST_VALUE and NTH_VALUE window functions to extract specific sales figures from monthly data. This lesson helps you write queries that dynamically identify first last and nth values to enhance your sales analytics skills.
We'll cover the following...
We'll cover the following...
Question
Consider the following Sales table structure:
SalesID | Month | SalesAmount |
1 | January | 1500 |
2 | February | 1400 |
3 | March | 1200 |
4 | April | 1600 |
5 | May | 800 |
6 | June | 6400 |
7 | July | 2400 |
8 | August | 2100 |
9 | September | 700 |
10 | October | 1000 |
11 | November | 5400 |
12 | December | 7400 |
As a sales analyst, you need to summarize key sales metrics for the year. Your goal is to write an SQL query that retrieves the sales data for each month. It should also highlight ...