表名为分钟数据A 
格式如下
I D      时间      压力   温度   湿度 
1         time1     10      15     20
2         time2     11      16     21
3         time3     12      17     22
4         time4     13      18     23 
5         time5     14      19     24
现在想把time1至time2之间的压力这列数据 替换成时间是time4到time5的压力的数据

解决方案 »

  1.   


    --> 测试数据:[test]
    if object_id('[test]') is not null drop table [test]
    create table [test](
    [ID] int,
    [时间] varchar(5),
    [压力] int,
    [温度] int,
    [湿度] int
    )
    insert [test]
    select 1,'time1',10,15,20 union all
    select 2,'time2',11,16,21 union all
    select 3,'time3',12,17,22 union all
    select 4,'time4',13,18,23 union all
    select 5,'time5',14,19,24update test
    set [压力]=t.[压力] from(
    select px=ROW_NUMBER()over(order by getdate()),
    [压力] from test where [时间] in('time4','time5')
    )t
    where test.ID=t.pxselect * from test
    /*
    ID 时间 压力 温度 湿度
    1 time1 13 15 20
    2 time2 14 16 21
    3 time3 12 17 22
    4 time4 13 18 23
    5 time5 14 19 24
    */说实话,你给的这个测试数据的时间字段让人很蛋疼
      

  2.   


    办法是有,关键是你举得这个例子太蛋疼了,不晓得怎么办。
    你要的是把time3--time4之间的压力字段的数据更新到time1--time2,你可以这样:update test
    set [压力]=t.[压力] from(
    select px=ROW_NUMBER()over(order by getdate()),
    [压力] from test where t.[时间] between time3 and time4)
    )t and test.[时间]between time1 and time2
      

  3.   


    I D     时间           压力     温度   湿度  
    1     2012-05-11     10       15     20
    2       2012-05-12     11       16     21
    3       2012-05-13     12       17     22
    4       2012-05-14     13       18     23  
    5       2012-05-15     14       19     24
    6     2012-05-16     15       15     20
    7       2012-05-17     17       16     21
    8       2012-05-18     11       17     22
    9       2012-05-19     18       18     23  
    10      2012-05-20     21       19     24
    11     2012-05-21     68       15     20
    12      2012-05-22     41       16     21
    13      2012-05-23     46       17     22
    14      2012-05-14     47       18     23  
    15      2012-05-25     14       19     24
    16     2012-05-26     16       15     20
    17      2012-05-27     54       16     21
    18      2012-05-28     57       17     22
    19      2012-05-29     59       18     23  
    20      2012-05-30     86       19     24
    21    2012-06-01     88       15     20
    22      2012-06-02     82       16     21
    23      2012-06-02     83       17     22
    24      2012-06-03     80       18     23  
    25      2012-06-04     16       19     24依你的意思,以上记录
    t1='2012-05-15'
    t2='2012-05-19'
    t4='2012-05-27'
    t5='2012-06-03'
    t4-t5这段时间段内有n个压力值,t1-t2时间段内有m条记录,怎么操作?这两个时间段有交叉的话怎么办