Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Trend Analysis

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL for Trend Analysis. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Write a SQL query to analyze a dataset and identify trends that could impact business decisions at MassMutual.

Use the provided policy and product data to evaluate monthly policy activity and premium trends during the first quarter of 2024. Include active and issued policies with non-null premiums, and exclude cancelled policies.

Output

  1. One row per product category and month, with product_category, month, policy_count, total_premium, prior_month_premium, and premium_change_pct.
  2. Include the prior available month for the same category and the percentage change, or NULL when unavailable.
  3. Order by product_category, then month ascending.

Schema

policies
ColumnTypeDescription
policy_idPKINTUnique policy identifier
product_idINTReferenced insurance product
issue_dateDATEDate the policy was issued
statusVARCHAR(20)Current policy status
premiumDECIMAL(12,2)Policy premium amount
products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Insurance product name
product_categoryVARCHAR(50)Product category used for trend analysis
Tablespoliciesproducts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results