问题描述
我有这个查询,我想要一个不使用递归 CTE 的替代查询.任何人都可以编辑和更新查询
I have this query and I want an alternative for this query without using recursive CTE. Can Anybody please edit and update the query
输出:
我尝试了以下查询,但它不起作用,任何人都可以更新此查询
I have tried below query but its not working,can anybody update this query
推荐答案
这是一种使用内联计数的方法:
This is a method using an inline tally:
不过,我个人建议你给自己一个日历表,那么问题就简单多了:
I do, personally, however, suggest you get yourself a Calendar Table, then the problem is far more simple:
两种解决方案都假设 from 日期应该在 to 日期之前之前;即使它在您的数据中似乎不正确.如果您的 from 日期可以是 after 您的 to 日期,我建议您有数据问题,因为如何开始strong> 之后结束?
Both solutions assume that the from date should be before the to date though; even though that it appears to not be true in your data. If your from date can be after your to date, I would suggest you have data issues, as how can something start after it has ended?
这篇关于将日期范围拆分为几个月(使用 CTE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!