读书人

sql server 在同一表下覆盖一段时间当

发布时间: 2012-05-21 18:04:41 作者: rapoo

sql server 在同一表下覆盖一段时间当中的一列数据。。
表名为分钟数据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的压力的数据



[解决办法]

SQL code
--> 测试数据:[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 allselect 2,'time2',11,16,21 union allselect 3,'time3',12,17,22 union allselect 4,'time4',13,18,23 union allselect 5,'time5',14,19,24update testset [压力]=t.[压力] from(select px=ROW_NUMBER()over(order by getdate()),[压力] from test where [时间] in('time4','time5'))twhere test.ID=t.pxselect * from test/*ID    时间    压力    温度    湿度1    time1    13    15    202    time2    14    16    213    time3    12    17    224    time4    13    18    235    time5    14    19    24*/说实话,你给的这个测试数据的时间字段让人很蛋疼 

读书人网 >SQL Server

热点推荐