How would you write SQL queries for different business scenarios at TikTok Shop?
Using the supplied TikTok Shop tables, produce a monthly seller performance result for January and February 2025. Include completed orders only and treat sellers without qualifying orders as zero activity.
Output
- One row per seller and month, with
seller_name, month, monthly_gmv, previous_month_gmv, month_over_month_change, monthly_rank, and cumulative_gmv.
- Include all sellers for both months, order by
month, monthly_rank, and seller_name.
Output details
- Represent each
month as the first day of the month, such as DATE '2025-01-01'.
- Calculate
monthly_gmv and cumulative_gmv with two decimal places.
- Set
previous_month_gmv to NULL for January and set month_over_month_change to NULL when the previous value is NULL or zero.
- Round non-NULL
month_over_month_change to two decimal places as a percentage.
- Treat month boundaries as inclusive at the start and exclusive at the following month's start.
- Assign tied monthly GMV values the same rank and retain every tied seller row.