建立两个表 A,B
A表大概结构如下,要存储一个月的数
leibie ,D1,D2,D3,D4,D5,D6,D7,D8...D29,D30,D31
B表大概结构如下,要存储10天的数据,可以是上旬、中旬、下旬其中之一
leibie ,d1,d2,d3,d4,d5,d6,d7,d8,d9,d10
我想要做的是当B表中数据生成之后的如何更新到A表中?
可能表述的不太明白,大体就是把B表一旬 的数据依照‘leibie’字段更新到A表对应项目中;

解决方案 »

  1.   

    写个过程用动态sql搞定吧!
    感觉表设计的不是很好,肯定有很多单元格没有值
      

  2.   

    要是一次性修改可以试试
    update a set (d1,d2,..d10) = (select d1,d2,..d10 from b where a.leibei=b.leibei)如果是即时的 考虑trigger
      

  3.   

    1、update a set (a.d1,a.d2,....)=(select b.d1,b.d2........ from b where b.leibie=a.leibie)
       where exists (select 1 from b where b.leibie=a.leibie);
       
    2、merge into a using b on (b.leibie=a.leibie)
     when mathed then
     update set a.d1=b.d1,a.d2=b.d2.........;3、update (select a.d1 ad1,a.d2 ad2....,b.d1 bd1,b.d2 bd2... from a,b where b.leibie=a.leibie)
       set ad1=bd1,ad2=bd2.....