上周日到下周六的 DB2 语句之间 [英] DB2 Between Statement for Last Sunday to This Coming Saturday
本文介绍了上周日到下周六的 DB2 语句之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很好奇为什么这不起作用:
I am curious why this does not work:
SELECT *
FROM TABLE
WHERE DATE_TIME_COLUMN BETWEEN
current date - int((dayofweek(current date))-1)
AND
current date + int(7-(dayofweek(current date)))
当这正是我想要的:
select current date - int((dayofweek(current date))-1) days from sysibm.sysdummy1)
select current date + int(7-(dayofweek(current date))) days from sysibm.sysdummy1)
以上两个将产生我希望我的特定日期时间列介于两者之间的正确日期.我在这里错过了什么?
The above two will yield the correct dates that I want my specific date time column to be in between. What am I missing here?
推荐答案
SELECT *
FROM TABLE
WHERE DATE_TIME_COLUMN BETWEEN
current date - ((dayofweek(current date))-1) DAYS
AND
current date + (7-(dayofweek(current date))) DAYS
如上所示,您必须表明您正在从当前日期减少 DAYS.
You have to signify that you are reducing DAYS from current date as shown above.
这篇关于上周日到下周六的 DB2 语句之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文