Write a SQL query to compare current-week and previous-week performance by segment using CTEs and window functions.
Assume the current week is January 15 through January 21, 2024, and the previous week is January 8 through January 14, 2024. Use segment_performance as the source table and include only segments with data in both weeks.
segment, current_week_performance, previous_week_performance, absolute_change, percentage_change, and current_rank.current_rank, then segment alphabetically.| Column | Type | Description |
|---|---|---|
| performance_idPK | INT | Unique performance record identifier |
| segment | VARCHAR(50) | Business segment associated with the performance record |
| performance_date | DATE | Date on which performance was recorded |
| performance_value | NUMERIC(12,2) | Performance amount recorded for the segment and date |