Ivy Professional School
Rating
Learning/SQL Data Drill #15

Quarter-wise Salesman Bonus Analysis

Last updated

Calculate the bonus earned by each salesman in each quarter based on sales targets and car make bonus rules.

SQLIntermediateCASE WHENCTEConditional AggregationGROUP BYPivot OutputBusiness Rules

Your Objective

Calculate the bonus earned by each salesman in each quarter based on sales targets and car make bonus rules.

The Setup

Your dataset contains two sales performance tables: 1. A Sales table with car make, type, style, sale value, purchase date, and salesman reference 2. A Salesman table with salesman IDs and names Analyze quarter-wise bonus earned by each salesman based on sales performance, car make bonus, and quarterly target achievement.

Table Schema

Sales
ColumnTypeKey / Notes
sale_idINTPK
makeVARCHAR(50)
typeVARCHAR(50)
styleVARCHAR(50)
cost_$DECIMAL(10,2)
purchased_dateDATE
salesman_idINTFK
Salesman
ColumnTypeKey / Notes
salesman_idINTPK
nameVARCHAR(50)

Sample Data

Salesman — 4 rows

salesman_idname
101John Doe
102Jane Smith
103Robert Brown
104Emily Davis

Sales — 9 rows

sale_idmaketypestylecost_$purchased_datesalesman_id
1HondaSedanAccord28002023-05-15104
2BMWSUVX560002023-02-20102
3AudiSedanA4450002022-11-13104
4FordTruckF-150400002023-07-24103
5NissanHatchbackCivic22002023-03-30103
6MercedesSedanC-Class450002022-09-17101
7ToyotaSUVGLC520002023-01-05102
8AudiSUVQ5550002022-08-21101
9BMWTruckFrontier280002023-04-18104

Car Make Bonus — 7 rules

Car MakeBonus per Sale
Honda200
Ford350
Audi400
Nissan120
Toyota270
BMW600
Mercedes590

Quarterly Sales Target — 4 rules

QuarterMonthsSales Target
Q1January, February, March100000
Q2April, May, June60000
Q3July, August, September1000000
Q4October, November, December1000000

Your Task

Quarter-wise Salesman Bonus Analysis: What is the total bonus received by each salesman in each quarter? Bonus rule: Bonus = 10% of total sales + car make bonus. If a salesman does not meet the sales target for a quarter, they receive only the car make bonus for that quarter. The final result table should have name, q1, q2, q3, and q4 columns.

Your output should look like this (partial example):

nameq1q2q3q4
Emily Davis08000400
Jane Smith870000
John Doe009900

Before You Solve

  • →Use MONTH(purchased_date) to convert every sale into a quarter number.
  • →Use CASE WHEN to calculate the make bonus for each car sale.
  • →Aggregate total sales and make bonus by salesman_id and quarter.
  • →Compare total_sales with the quarter target before deciding whether to add the 10% sales bonus.
  • →Use conditional aggregation to pivot quarter-wise bonus rows into q1, q2, q3, and q4 columns.
Explore Enterprise Solutions