In part 1 we went back to the basics in this part I want to show more advanced possibility's.
Consider the following question: How much do my customers contribute to my sales on a yearly basis?
This means we have to have at least two numbers in the same query:
- Total Sales per year.
- Total Sales per year per customer.
To achieve this we can use the “PARTITION BY” clause in the “OVER ()” statement:
Don’t panic if you see the same number reappearing in SalesPerYearPerCustomer column. This is caused by the fact that the people who made the AdventureWorks base set weren’t very creative with the orders…….
To work around this I added an extra column named SalesAmountReal and filled this with a randomized amount:
This would give us:
Even in my randomized set there isn’t a huge spread in sales amount.
Till Next Time
No comments:
Post a Comment