select days from t1days 爲 datetime類型,但是用戶在保存數據的時候,只有日期 2011-05-03 00:00:00.000
2011-05-03 00:00:00.000
2011-05-03 00:00:00.0002011-05-05 00:00:00.000
2011-05-05 00:00:00.0002011-05-06 00:00:00.000
2011-05-07 00:00:00.000現需要以日期爲主鍵查詢數據,所以希望能增加分鍾數日期相同時,分鍾數遞增12011-05-03 00:00:00.000
2011-05-03 00:00:01.000
2011-05-03 00:00:02.0002011-05-05 00:00:00.000
2011-05-05 00:00:01.0002011-05-06 00:00:00.000
2011-05-06 00:00:01.000
2011-05-06 00:00:02.000
2011-05-06 00:00:03.0002011-05-07 00:00:00.000

解决方案 »

  1.   

    ---测试数据---
    if object_id('[t1]') is not null drop table [t1]
    go
    create table [t1]([days] datetime)
    insert [t1]
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-05 00:00:00.000' union all
    select '2011-05-05 00:00:00.000' union all
    select '2011-05-06 00:00:00.000' union all
    select '2011-05-07 00:00:00.000'
     
    ---查询---
    select days=dateadd(mi,row_number() over(partition by days order by getdate())-1,days) from [t1]
    ---结果---
    days
    -----------------------
    2011-05-03 00:00:00.000
    2011-05-03 00:01:00.000
    2011-05-03 00:02:00.000
    2011-05-05 00:00:00.000
    2011-05-05 00:01:00.000
    2011-05-06 00:00:00.000
    2011-05-07 00:00:00.000(7 行受影响)
      

  2.   


    create table t1
    (
    riqi datetime
    )
    insert into t1
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-05 00:00:00.000' union all
    select '2011-05-05 00:00:00.000' union all
    select '2011-05-06 00:00:00.000' union all
    select '2011-05-06 00:00:00.000' union all
    select '2011-05-06 00:00:00.000' union all
    select '2011-05-06 00:00:00.000' union all
    select '2011-05-07 00:00:00.000'
    select * from t1;with aaa as
    (select ROW_NUMBER() over(partition by riqi order by riqi) as row,* from t1)
    update aaa set riqi=DATEADD(MINUTE,row-1,riqi) from aaa
      

  3.   


    數據庫sql2000,好象不能用with吧
    我木說清楚。sorry.
      

  4.   

    --sql2000
    if object_id('[t1]') is not null drop table [t1]
    go
    create table [t1]([days] datetime)
    insert [t1]
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-03 00:00:00.000' union all
    select '2011-05-05 00:00:00.000' union all
    select '2011-05-05 00:00:00.000' union all
    select '2011-05-06 00:00:00.000' union all
    select '2011-05-07 00:00:00.000'
    alter table t1 add tid int identity(1,1);
    goupdate t1
    set days=dateadd(mi,(select count(1) from t1 where days=t.days and tid<t.tid),days)
    from t1 t
    goalter table t1 drop column tid;
    goselect * from t1
    /**
    days
    -----------------------
    2011-05-03 00:00:00.000
    2011-05-03 00:01:00.000
    2011-05-03 00:02:00.000
    2011-05-05 00:00:00.000
    2011-05-05 00:01:00.000
    2011-05-06 00:00:00.000
    2011-05-07 00:00:00.000(7 行受影响)
    **/