得出一天的时间段记录。(如 1:00-2:00) if OBJECT_ID('fn_time') is not null drop function fn_time go create function fn_time (@n int)--每隔n小时一段 returns table as return( select 时间段=right(100+number*@n,2)+':00-'+right(100+(number+1)*@n,2)+':00' from master..spt_values where type='p' and number <= 23/@n and 24%@n=0 ) GO select * from fn_time(3) /* 时间段 00:00-03:00 03:00-06:00 06:00-09:00 09:00-12:00 12:00-15:00 15:00-18:00 18:00-21:00 21:00-24:00 */
生成当天每隔n小时的时间列表
最新推荐文章于 2025-07-27 23:21:05 发布
本文介绍了一个SQL函数fn_time,该函数可以根据指定的小时数间隔生成一天内的各个时间段记录,适用于需要按固定时间间隔统计数据的应用场景。
7898

被折叠的 条评论
为什么被折叠?



