Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rank Users or Sellers With Window Functions

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

Your question is Rank Users or Sellers With Window Functions. 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 using window functions to rank users or sellers by performance.

For this exercise, rank all sellers by the total value of their completed orders. Include sellers with no completed orders, and assign the same rank to sellers with equal totals.

Output

  1. One row per seller, with seller_id, seller_name, total_completed_gmv, and performance_rank
  2. Include every seller, including those with no completed orders
  3. Sort by total_completed_gmv descending, then seller_id ascending for ties

Schema

sellers
ColumnTypeDescription
seller_idPKINTUnique seller identifier
seller_nameVARCHAR(100)Seller display name
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
seller_idINTSeller associated with the order
statusVARCHAR(30)Current order status
order_valueNUMERIC(12,2)Order merchandise value
Tablessellersorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results