Dataford
Interview Guides
Upgrade
All questions/SQL & Data Manipulation/Analyze Quarterly Variance Drivers by Product

Analyze Quarterly Variance Drivers by Product

Hard
SQL & Data Manipulation

Problem

Task

A financial analysis team needs to assess the variance drivers affecting quarterly performance for different product categories. Write a SQL query to summarize the total revenue and compare it to the previous quarter's revenue to identify variance drivers.

Requirements

  1. Calculate total revenue for each product category for the current and previous quarters.
  2. Compute the variance in revenue between the two quarters.
  3. Rank categories based on the variance amount.
  4. Filter results to show only categories with a variance greater than a specified threshold.

Schema

sales (id, product_category, transaction_date, amount)

idproduct_categorytransaction_dateamount
1Electronics2024-01-15300
2Clothing2024-01-20150
3Electronics2024-02-15400
4Clothing2024-02-10250
5Books2024-01-05200
6Electronics2024-03-01500
7Books2024-03-15300
8Clothing2024-03-20350

Expected Output

product_categorycurrent_quarter_revenueprevious_quarter_revenuevariancerank
Electronics12007005001
Clothing8004004002
Books5003002003

Schema

sales
ColumnTypeDescription
idPKINTPrimary key
product_categoryVARCHAR(255)Category of the product sold
transaction_dateDATEDate of the transaction
amountDECIMAL(10,2)Revenue amount from the transaction

sales

idproduct_categorytransaction_dateamount
1Electronics2024-01-15300
2Clothing2024-01-20150
3Electronics2024-02-15400
4Clothing2024-02-10250
5Books2024-01-05200
6Electronics2024-03-01500
7Books2024-03-15300
8Clothing2024-03-20350

Problem

Task

A financial analysis team needs to assess the variance drivers affecting quarterly performance for different product categories. Write a SQL query to summarize the total revenue and compare it to the previous quarter's revenue to identify variance drivers.

Requirements

  1. Calculate total revenue for each product category for the current and previous quarters.
  2. Compute the variance in revenue between the two quarters.
  3. Rank categories based on the variance amount.
  4. Filter results to show only categories with a variance greater than a specified threshold.

Schema

sales (id, product_category, transaction_date, amount)

idproduct_categorytransaction_dateamount
1Electronics2024-01-15300
2Clothing2024-01-20150
3Electronics2024-02-15400
4Clothing2024-02-10250
5Books2024-01-05200
6Electronics2024-03-01500
7Books2024-03-15300
8Clothing2024-03-20350

Expected Output

product_categorycurrent_quarter_revenueprevious_quarter_revenuevariancerank
Electronics12007005001
Clothing8004004002
Books5003002003

Schema

sales
ColumnTypeDescription
idPKINTPrimary key
product_categoryVARCHAR(255)Category of the product sold
transaction_dateDATEDate of the transaction
amountDECIMAL(10,2)Revenue amount from the transaction

sales

idproduct_categorytransaction_dateamount
1Electronics2024-01-15300
2Clothing2024-01-20150
3Electronics2024-02-15400
4Clothing2024-02-10250
5Books2024-01-05200
6Electronics2024-03-01500
7Books2024-03-15300
8Clothing2024-03-20350
Practice SQL
PostgreSQL
Open on desktop for the full SQL editor with syntax highlighting and autocomplete.
Up next
ASI (Advertising Specialty Institute)Analyze Monthly Revenue Trends by Product CategoryMediumHD SupplyMonthly Sales Trends by CategoryMediumRipplingVariance Analysis in SQL ReportingEasy
Next question