問題文
A weekly summary must show total sales for the current week and the same figure for the previous week, side by side on one row. Which construct produces that shape most directly?
選択肢
- Use a scalar subquery per row that sums the previous week, correlated on the week column.
- Aggregate by week, then use LAG over the ordered weeks to bring the previous week's total onto the same row.
- Use LAG on the detail rows before aggregating, so that each row carries the previous week's value and the weekly totals line up.
- Aggregate by week twice for the current week in the same query and join the two aggregates on a week offset of one.