Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Basic Joins and Window Functions

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

Your question is Basic Joins and Window Functions. Start with the requirements and the four 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

TikTok Shop analytics needs to identify how creators contribute to product-category sales. Write a PostgreSQL query that joins four tables, calculates completed January 2026 GMV for each creator and category, and ranks creators within each category.

Requirements

  1. Join creators to their TikTok Shop videos, products, and orders.
  2. Count distinct promoted videos and completed orders, and calculate GMV as quantity * unit_price.
  3. Include only orders from January 2026 with status COMPLETED; retain creators and videos that have no qualifying orders.
  4. Use ROW_NUMBER() to rank creators within each category by GMV descending, then completed orders descending, then creator ID ascending. Return all ranked rows.

Schema

creators
ColumnTypeDescription
creator_idPKINTUnique creator identifier
creator_handleVARCHAR(50)TikTok creator handle
videos
ColumnTypeDescription
video_idPKINTUnique TikTok video identifier
creator_idINTCreator who published the video
product_idINTTikTok Shop product promoted by the video
products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Product display name
categoryVARCHAR(50)Product category
shop_orders
ColumnTypeDescription
order_idPKINTUnique order identifier
video_idINTTikTok Shop video attributed to the order
order_dateDATEDate the order was placed
statusVARCHAR(20)Order fulfillment status
quantityINTNumber of units ordered
unit_priceNUMERIC(10,2)Price per unit at purchase time
Tablescreatorsvideosproductsshop_orders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results