program

pssql 일괄 업데이트 쿼리 예

꿀항아리_ 2014. 12. 26. 16:20
반응형



update test m set pkum  = (case u.cd when '2' then pkum  - u.janyear else pkum  end),

                          rkum  = (case u.cd when '1' then rkum - u.janyear else rkum end),

                          dt      = (case u.cd when '2' then dt - janmon else dt end),

                          ct      = (case u.cd when '1' then ct - janmon else ct end)

  from ( select s.member_mid, blsbcode, mbacode1, cd ,

          sum(case when mbcheck <> '' and (substr(blaccode,1,1)='b' or substr(blaccode,1,1)='p')

                     then case cd when '1' then coalesce(dt,0)

                                      else coalesce(dt,0) end

                else  0 end)::numeric janmon,

      sum(case when mbcheck <> '' and (substr(blaccode,1,1)='b' or substr(blaccode,1,1)='p')

                           then case cd when '1' then coalesce(pkum,0)

                                              else coalesce(rtkum,0) end

                     else 0 end )::numeric janyear

          from test s left outer join accset c

            on s.member_mid= c.member_mid

          and s.blaccode = c.mbacode

       where s.member_mid='test'

         and s.blsbcode='00'

         and mbcheck <> ''

         and coalesce(c.mbacode1,'') <>  ''

      group by s.member_mid, blsbcode, mbacode1, cd  ) u

where m.member_mid = u.member_mid

   and m.blsbcode = u.blsbcode

   and m.blaccode = u.mbacode1

반응형