计算偏移量的开始日期和结束日期之间的天数(Calculate days between Start and End date at an offset)

编程入门 行业动态 更新时间:2024-10-26 03:28:10
计算偏移量的开始日期和结束日期之间的天数(Calculate days between Start and End date at an offset)

我在SQL中使用以下列创建了一个Calendar Table:

现在我有一个开始日期,结束日期和偏移量,并且必须计算天数,如下所述:

start date: 1-12-2016----End date: 10-12-2016----Offset: 2

输出:

1-12-2016 3-12-2016 5-12-2016 7-12-2016 9-12-2016

我似乎无法想到这个问题的查询。 在这方面的任何帮助将受到高度赞赏。

I have created a Calendar Table in SQL with these columns:

Now I have a start date, end date and an offset, and have to calculate days as explained below:

start date: 1-12-2016----End date: 10-12-2016----Offset: 2

Output:

1-12-2016 3-12-2016 5-12-2016 7-12-2016 9-12-2016

I cant seem to be able to think a query for this. Any help in this regard will be highly appreciated.

最满意答案

使用模运算:

select c.date from calendar c where c.date >= @startdate and c.date <= @enddate and datediff(day, @startdate, c.date) % @offset = 0

Use modulo arithmetic:

select c.date from calendar c where c.date >= @startdate and c.date <= @enddate and datediff(day, @startdate, c.date) % @offset = 0

更多推荐

本文发布于:2023-08-06 12:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   天数   结束   偏移量   Calculate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!