Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Products by Monthly Share
00:00
5 left

Top Products by Monthly Share

MediumSQL · PostgreSQL

Problem

Groww's Business Analytics team wants to compare which investment products contribute the most and least to monthly completed order value. Write a PostgreSQL query that calculates each product's share of monthly sales and returns the top five and last five products for every month.

Requirements

  1. Join completed sales to the product catalog and aggregate sales amount by calendar month and product.
  2. Calculate each product's percentage share of its month's total sales.
  3. Return both the five highest-ranked and five lowest-ranked products for each month.
  4. Include a segment label, TOP 5 or LAST 5, and use deterministic ranking by revenue and product_id.

Schema

products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Groww product name
categoryVARCHAR(50)Product category
sales
ColumnTypeDescription
sale_idPKINTUnique sale identifier
product_idINTReferenced product identifier
sold_atTIMESTAMPTimestamp when the sale was recorded
amountNUMERIC(12,2)Monetary value of the sale
statusVARCHAR(20)Transaction processing status
Tablesproductssales
Interviewer

Your question is Top Products by Monthly Share. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.