Bunch of weird stuff about sql. Explain each function, method, etc. Basics for python, what is def, how to write a loop, etc.
For this SQL exercise, write one query that summarizes qualifying customer orders and demonstrates common PostgreSQL query functions.
Output
- One row per customer, including customers without qualifying orders.
- Return
customer_id, customer_name, order_count, total_spend, avg_order_value, categories, customer_tier, and revenue_rank.
- Include completed or pending orders from 2024-01-01 through 2024-03-31, exclude cancelled orders, and order by
revenue_rank, then customer_id.
Output details
- Use qualifying order dates from
2024-01-01 inclusive through 2024-04-01 exclusive.
- Use
0 for total_spend and avg_order_value when no qualifying orders exist.
- Round
avg_order_value to exactly two decimal places.
- List distinct categories alphabetically, separated by
, , and use No category when none exist.
- Assign
Premium for totals at least 400, Standard for totals at least 200, and Starter otherwise.
- Rank customers by
total_spend descending, assigning the same rank to ties.