Preppin Data with SQL (2024Wk3)

Here is the challenge: https://preppindata.blogspot.com/2024/01/2024-week-3-performance-against-targets.html

The task is to link our original sales data with a new quarterly sales target data source an ascertain if Prep Air is meeting its targets. Here are the steps:

Step 1: Bring in the three sheets

Step 2: Union flow and nonflow sets

We split these up in week 1. We want em back together today.

We're back!

Step 3: Correct Class Names as per Week 2

Updating the table with a case statement should do the trick.

Step 4: Aggregate to a monthly level, for each flight class

MONTH([date]) should give us the month number. Use TO_DATE() to convert the date string into a date. GROUP BY to aggregate!

Step 5: Join Sales and Target Data

To do this we need to isolate the first letter of the class field within each data set and carrying out an inner join. The LEFT function is handy here! We'll use this opportunity to get rid of some unwanted fields by leaving them out of our SELECT statement.

Step 6: Calculate Variance to Target and Create Output Table

Just a simple calculated field and a 'CREATE TABLE':

Success! See you in the next one.

Author:
Dominic Brady
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2025 The Information Lab