检索前6天的数据

问题描述 投票:0回答:1

我有这样的要求:我需要获取特定日期范围之间的数据,例如当我输入日期范围时,请考虑我输入2017-05-01和2017-05-31。

要求是:

  1. 我只需要获取该日期范围内前0-6天的数据。

  2. 我只需要获取该日期范围内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天]中显示它们。

任何人都可以帮忙吗?

sql sql-server stored-procedures reporting-services ssrs-2008
1个回答
0
投票

您不需要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
© www.soinside.com 2019 - 2024. All rights reserved.