我有这样的要求:我需要获取特定日期范围之间的数据,例如当我输入日期范围时,请考虑我输入2017-05-01和2017-05-31。
要求是:
我只需要获取该日期范围内前0-6天的数据。
我只需要获取该日期范围内7-13天的数据。
我在下面的查询中使用了0-6天的日期:
select date as first6days
from data
where cast(d.d_create_date as date) between cast('2019-05-01' as date)
and cast(dateadd(dd,6,'2019-05-31') as date)
但是显示的是6天内的日期以及该日期段内的下一个日期。
为了获得仅前6天的日期,我需要做哪些更改,如果不是前6天,我需要在[7-13天]中显示它们。
任何人都可以帮忙吗?
您不需要end date
来满足此要求。您只需要start date
。
开始的前6天
cast(d.d_create_date AS date) between cast('2019-05-01' as date) and cast('2019-05-01' as date) + 6
第7至13天开始
cast(d.d_create_date AS date) between cast('2019-05-01' as date) + 7 and cast('2019-05-01' as date) + 13