; com pivotdate como (selecionar o dateadd (wk, 17, “20100101”) como DayInWkNumX)
, keyDates (FirstDayNextWeek, FirstDay9WeeksAgo, FirstDayNextWeekOneYearAgo, FirstDay9WeeksAgoOneYearAgo)
como (
seleto
DATEADD (wk, datediff (wk, 0, DayInWkNumX) +1.0),
DATEADD (wk, datediff (wk, 0, DayInWkNumX) - 9.0),
dateadd (JJ, - 1, DATEADD (wk, datediff (wk, 0, DayInWkNumX) +1.0)),
dateadd (JJ, - 1, DATEADD (wk, datediff (wk, 0, DayInWkNumX) - 9.0))
do pivotdate
)
selecionar Weeks10ToToday, Weeks10ToTodayOneYearAgo
de
(SOMA seleta (somevalue) COMO Weeks10ToToday dos keyDates
interno juntar-se a MyTable
no >= FirstDay9WeeksAgo do datefield e no datefield < FirstDayNextWeek="">= no FirstDay9WeeksAgoOneYearAgo e no datefield < FirstDayNextWeekOneYearAgo="">
|