如图,那其中一个企业为例:怎么将ssgs为空值得值更新为相同企业名称下的有值得值

解决方案 »

  1.   


    update sr_qfjg t
    set (ssgs,qyxz)=(select distinct ssgs,qyxz from sr_qfjg where nsrmc=t.nsrmc);
     
    这样查询中的值select distinct ssgs,qyxz from sr_qfjg where nsrmc=t.nsrmc 查出来必须是单行值。
      

  2.   

    update table t1 set t1.ssgs=(select  max(t2.ssgs) from table t2 where t1.企业名称=t2.企业名称) where t1.ssgs is null
      

  3.   

    update 的时候尽量加where条件,否则将会进行全表扫描
      

  4.   

    就是说nsrmc相同的公司,ssgs,qyxz的值要一致,可以加一个ssgs is not null来筛选掉空值。update sr_qfjg t
    set (ssgs,qyxz)=(select distinct ssgs,qyxz from sr_qfjg where nsrmc=t.nsrmc and ssgs is not null);
      

  5.   

    update 的时候尽量加where条件,否则将会进行全表扫描