2 个解决方案
#1
给点数据及要的结果
#2
你想查看先后两天数据检查接近整天的数据吗?
比如下面的数据我cha'k
比如下面的数据我cha'k
/*
WITH a(ID,d) AS (
SELECT 1,'1/15/2016 06:13:50' UNION
SELECT 2,'1/15/2016 22:13:50' UNION
SELECT 3,'1/16/2016 06:13:50' UNION
SELECT 4,'1/16/2016 18:13:50' UNION
SELECT 5,'1/17/2016 06:13:50'
)
SELECT * INTO #a FROM a
*/
SELECT DATEDIFF(hh,a1.d,aa.d),* FROM #a AS a1
OUTER APPLY (SELECT a2.d FROM #a AS a2 WHERE a2.id=a1.id+1) aa
WHERE DATEDIFF(hh,a1.d,aa.d) BETWEEN 11 AND 13
#1
给点数据及要的结果
#2
你想查看先后两天数据检查接近整天的数据吗?
比如下面的数据我cha'k
比如下面的数据我cha'k
/*
WITH a(ID,d) AS (
SELECT 1,'1/15/2016 06:13:50' UNION
SELECT 2,'1/15/2016 22:13:50' UNION
SELECT 3,'1/16/2016 06:13:50' UNION
SELECT 4,'1/16/2016 18:13:50' UNION
SELECT 5,'1/17/2016 06:13:50'
)
SELECT * INTO #a FROM a
*/
SELECT DATEDIFF(hh,a1.d,aa.d),* FROM #a AS a1
OUTER APPLY (SELECT a2.d FROM #a AS a2 WHERE a2.id=a1.id+1) aa
WHERE DATEDIFF(hh,a1.d,aa.d) BETWEEN 11 AND 13