; с pivotdate как (выберите dateadd (wk, 17, «20100101») как DayInWkNumX)
, keyDates (FirstDayNextWeek, FirstDay9WeeksAgo, FirstDayNextWeekOneYearAgo, FirstDay9WeeksAgoOneYearAgo)
как (
отборно
DATEADD (wk, datediff (wk, 0, DayInWkNumX) +1.0),
DATEADD (wk, datediff (wk, 0, DayInWkNumX) - 9.0),
dateadd (yy, - 1, DATEADD (wk, datediff (wk, 0, DayInWkNumX) +1.0)),
dateadd (yy, - 1, DATEADD (wk, datediff (wk, 0, DayInWkNumX) - 9.0))
от pivotdate
)
выберите Weeks10ToToday, Weeks10ToTodayOneYearAgo
от
(отборная СУММА (somevalue) КАК Weeks10ToToday от keyDates
внутренне соедините MyTable
на >= FirstDay9WeeksAgo datefield и datefield < FirstDayNextWeek="">= FirstDay9WeeksAgoOneYearAgo и datefield < FirstDayNextWeekOneYearAgo="">
|