zoukankan      html  css  js  c++  java
  • 简单的SQl时间序列生成,每次时间间隔10分钟。

    create table #timeseries(Times datetime not null)
    go
    declare @firstdate datetime , @lastdate datetime
    declare @MI int
    begin
    set @firstdate='8/8/2012 6:00'
    set @lastdate ='8/9/2012 6:00'
    set @MI=datediff(MI,@firstdate,@lastdate)
    --嵌套循环
    while(@MI>=0)
    begin
    insert into #timeseries
    values(@firstdate)
    SET NOCOUNT ON
    set @firstdate=dateadd(MI,10,@firstdate)--每次起始时间递增10分钟。
    set @MI=datediff(MI,@firstdate,@lastdate) --当@firstdate递增至与@lastdate相同时,MI为0,退出循环
    SET NOCOUNT Off
    end
    end
    select ROW_NUMBER() over(order by Times) as id, CONVERT(varchar(10),Times, 120 ) as 日期 ,Times from #timeseries order by Times asc
    drop table #timeseries

  • 相关阅读:
    工厂增强
    面试题
    SpringBean生命周期及作用域
    字符串
    带参数方法实例
    带参数方法
    人机猜拳
    类的无参方法
    类和对象实例2
    类和对象实例1
  • 原文地址:https://www.cnblogs.com/hclw/p/6993276.html
Copyright © 2011-2022 走看看