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.
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.
quantity * unit_price.COMPLETED; retain creators and videos that have no qualifying orders.ROW_NUMBER() to rank creators within each category by GMV descending, then completed orders descending, then creator ID ascending. Return all ranked rows.| Column | Type | Description |
|---|---|---|
| creator_idPK | INT | Unique creator identifier |
| creator_handle | VARCHAR(50) | TikTok creator handle |
| Column | Type | Description |
|---|---|---|
| video_idPK | INT | Unique TikTok video identifier |
| creator_id | INT | Creator who published the video |
| product_id | INT | TikTok Shop product promoted by the video |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(100) | Product display name |
| category | VARCHAR(50) | Product category |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| video_id | INT | TikTok Shop video attributed to the order |
| order_date | DATE | Date the order was placed |
| status | VARCHAR(20) | Order fulfillment status |
| quantity | INT | Number of units ordered |
| unit_price | NUMERIC(10,2) | Price per unit at purchase time |