如何使用查询获取两个给定日期之间的月份列表?
我有 2 个日期,比如 2011 年 3 月 28 日和 2011 年 6 月 29 日。我需要一个 sql 查询来显示这两个日期之间的月份,包括包含日期的月份,即。六月、五月、四月和三月。
I have 2 dates, say 28-Mar-2011 and 29-Jun-2011. I need an sql query that will display the months between these 2 dates including the months containing the dates, ie. June, May, April and March.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
像这样的东西
应该有效。
Something like this
should work.
添加这个解决方案只是因为我认为它比其他解决方案干净得多:
Gonna add this solution just because I think it's much cleaner than the others:
您可以使用函数 MONTHS_BETWEEN
输出
You can use the function MONTHS_BETWEEN
Output
几天前我需要这个问题的答案。我找到了另一个我更喜欢的解决方案:
您当然可以使用任何您想要的格式。我“联合”并总结了另一组数据,这样即使他们没有结果,我也能得到几个月的数据。
I needed an answer to this a couple of days ago. I found another solution I liked more:
You could of course use any format you want. I 'union'ed and summed over another set so that I'd get the months even when they didn't have results.
此处,月份名称为克罗地亚语
Here, month names are in Croatian