本文介绍了如何在mysql查询中使用datebackbone,就像在mssql查询中一样......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
declare @Date1 Datetime, @Date2 DateTime
set @Date1 = '2016/1/1 00:00:00'
set @Date2 = @Date1 + DATEDIFF(d,'2016/1/1 00:00:00', '2016/1/31 23:59:59' )
SELECT Day(Date) AS DDate,Month(Date) AS MDate,Year(Date) as YDate
FROM dbo.DateBackbone( @Date1, @Date2)
我试过的:
我还没有在MySql查询中找到使用DateBackBone函数它在MS_Sql Server查询中工作!
What I have tried:
I have not found using DateBackBone function in MySql query it is work in MS_Sql Server query!
推荐答案
declare @Date1 Datetime = '2016-1-1 00:00:00'
declare @Date2 DateTime = @Date1 + DATEDIFF(d,'2016-1-1 00:00:00', '2016-1-31 23:59:59' )
;WITH q AS
(
SELECT @Date1 AS datum
UNION ALL
SELECT datum + 1
FROM q
WHERE datum + 1 <= @Date2
)
SELECT Day(datum) AS DDate,Month(datum) AS MDate,Year(datum) as YDate
FROM q
我从 [](免责声明:我很有礼貌d与该文章的共同作者,但这项工作来自@ManasBhardwaj)
which I took from Generating a Sequence in SQL[^] (Disclaimer: I am credited with co-authorship of that article, but this work is from @ManasBhardwaj)
这篇关于如何在mysql查询中使用datebackbone,就像在mssql查询中一样......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!