0

我们有一个包含多个字段的表,例如 300+。结构是这样的:storenum, Monval1, Monval2... Monval45, Monval46... Tuesval1, Tuesval2 等等。基本上对于值 1 到 53,一周中的每一天都有一个版本,因此 53 个字段 * 7 天加上一些其他随机字段。

我需要使用来自商店 1 的数据更新商店 3 到 285。我尝试了什么:

Update (Select MonVal1... SunVal53 from table1 
 where storenum in (3, 4,...284,285)) as Dest
From (Select MonVal1... SunVal53 from table1 
 where storenum =1) as Source

但它是一个nogo。

我想做的事情甚至可以完成吗?

4

2 回答 2

0

您可以编写此模式的超长更新语句:

UPDATE badly_normalized_table
SET monval1 =   ( SELECT monval1 FROM badly_normalized_table WHERE ... )
WHERE pk = the_pk_you_want_to_upate
于 2012-08-21T17:17:33.523 回答
0
Update table1 set
    MonVal1    = origin.MonVal1, 
    /* the orher fields here */
    SunVal53   = origin.SunVal53
from table1
inner join table1 as origin on origin.storenum = 1
where table1.storenum in (3, 4,...284,285)
于 2012-08-21T17:27:29.470 回答