日期:2014-05-17 浏览次数:20525 次
DECLARE @a TABLE(a VARCHAR(5),b FLOAT)
INSERT @a SELECT '10:34',28.5
UNION ALL SELECT '10:35',20.5
UNION ALL SELECT '10:36',20.5
UNION ALL SELECT '10:37',20.5
UNION ALL SELECT '10:38',20.5
UNION ALL SELECT '10:39',20.5
UNION ALL SELECT '10:40',20.5
UNION ALL SELECT '10:42',21.5
UNION ALL SELECT '10:43',20.5
UNION ALL SELECT '10:44',20.5
UNION ALL SELECT '10:50',29.5
UNION ALL SELECT '10:51',51.5
UNION ALL SELECT '10:52',20.5
UNION ALL SELECT '10:53',20
UNION ALL SELECT '10:54',20
UNION ALL SELECT '10:55',20.5
UNION ALL SELECT '10:56',28.5
UNION ALL SELECT '10:57',9.5
SELECT convert(char(5),aa.a,108)a, COALESCE(bb.b,(SELECT TOP 1 b FROM @a WHERE a>aa.a ORDER BY a ),(SELECT TOP 1 b FROM @a WHERE aa.a>a ORDER BY a desc)) value
FROM
( SELECT distinct DATEADD (mi,sv.number,'10:27') a
FROM MASTER.dbo.spt_values sv WHERE sv.number BETWEEN 1 AND 31
)aa LEFT JOIN @a bb
ON aa.a=bb.a
--result
/*a value
----- -----------------------------------------------------
10:28 28.5
10:29 28.5
10:30 28.5
10:31 28.5
10:32 28.5
10:33 28.5
10:34 28.5
10:35 20.5
10:36 20.5
10:37 20.5
10:38 20.5
10:39 20.5
10:40 20.5
10:41 21.5
10:42 21.5
10:43 20.5
10:44 20.5
10:45 29.5
10:46 29.5
10:47 29.5
10:48 29.5
10:49 29.5
10:50 29.5
10:51 51.5
10:52 20.5
10:53 20.0
10:54 20.0
10:55 20.5
10:56 28.5
10:57 9.5
10:58 9.5
(所影响的行数为 31 行)
*/