Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Fastest-Growing Seller Revenue

HardSQL · PostgreSQL00:00
I
Practice interviewer
In session
5 left
00:00

Your question is Rank Fastest-Growing Seller Revenue. Start with the requirements and the one table 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

You are given seller order data from a marketplace. Write a PostgreSQL query that identifies the sellers whose revenue is growing fastest month over month, based on the largest percentage increase in the latest month compared with the previous month. Return one row per seller with their latest month, previous month revenue, growth amount, and growth rate, then rank sellers from highest to lowest growth rate.

Use window functions to compare each seller’s monthly revenue to the prior month. Exclude sellers who do not have revenue in both months needed for the comparison.

Schema

seller_orders
ColumnTypeDescription
order_idPKINTPrimary key for each order
seller_idINTUnique seller identifier
seller_nameVARCHAR(255)Seller display name
order_dateDATEDate the order was completed
order_revenueDECIMAL(10,2)Revenue from the order
Tablesseller_orders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results