Your question is Bucket Users by Order Count. 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.
ShopWave wants a simple user segmentation report based on how many orders each user has placed. Write a PostgreSQL query that buckets users into segments using CASE WHEN.
user_segment column using these rules based on order_count:
New for order_count = 0Light for order_count between 1 and 4Active for order_count between 5 and 9Power for order_count >= 10Unknown when order_count is NULLuser_count, ordered by user_count descending and then user_segment ascending.| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Primary key for each user |
| user_name | VARCHAR(100) | User name |
| order_count | INT | Total number of orders placed by the user |
| signup_source | VARCHAR(50) | Marketing channel where the user signed up |