如何选择特定的日期范围?

时间:2015-11-02 13:44:10

标签: sql date db2

SELECT TYPE, TERMINAL, PERIOD_NUMBER, WEEK, DM FROM 
(SELECT 'ACTUAL' AS TYPE, TERMINAL, PERIOD_NUMBER, "WEEK", SUM(CASE WHEN TYPE = 'REVENUE' THEN TOTAL ELSE 0 END - CASE WHEN TYPE = 'EXPENSE' THEN TOTAL ELSE 0 END) DM FROM BT_CU_DM_TERMINAL
WHERE TERMINAL NOT IN ('99','88')
GROUP BY TERMINAL, PERIOD_NUMBER, "WEEK"
UNION
SELECT 'BUDGET' AS TYPE, RIGHT(GL_ACCT_ID, 2) TERMINAL, PERIOD_NUMBER, WEEK(CURRENT DATE - 5 DAYS) "WEEK", 
CASE WHEN WEEK(CURRENT DATE - 5 DAYS) IN (40, 41, 42, 43, 44, 53,1,2,3,4,5, 14,15,16,17,18,27,28,29,30,31) THEN BUDGET_AMT/5 ELSE BUDGET_AMT/4 END DM FROM GL_BUDGETS WHERE
FISCAL_YEAR_CODE = '2015' AND GL_ACCT_ID LIKE '01-6999-%'
ORDER BY PERIOD_NUMBER, WEEK, TERMINAL)

我正在使用DB2并且我正在尝试找到一个合适的WHERE子句,以便动态拉动当前周;无论何时使用此声明。 例如我们在第44周;然而,当下周到处滚动时,我希望它能在本周显示出来。

谢谢!

1 个答案:

答案 0 :(得分:0)

本周可以通过objects获得。