更新多個表的不同欄位到乙個表中

2021-07-25 23:59:21 字數 2960 閱讀 5842

update eval_infraction ei

#關聯車,證,企業資訊

left

join

( select ci.veh_status,ci.veh_type_one,ci.veh_type_two,ci.total_kg,ci.plate_brand,ci.engine_num,

ci.veh_framenum,ci.veh_color,ci.address,ci.vehicle_master,ci.veh_plate_num,ci.ent_name,ci.ent_code,

c.exam_date,c.trading_card,c.ent_dlysjyxkz,c.bus_scope,e.address as mesaddress,e.representative

from car_vehicle_info ci

left

join car_vehicle_card c on ci.id = c.info_id and c.state = 1

left

join ent_enterprise_info e on ci.ent_code = e.organ_code

) cvi

on ei.vehicle_merge_plate = cvi.veh_plate_num

#關聯人員資訊

left

join wks_worker ww

on ei.worker_*****s_no = ww.*****s_no

#關聯執法人員資訊

left

join

( select e.administratorid,m.departmentid,e.administratorname,u.username,m.departmentname,e.plateno

from eval_marshalling_plate e

left

join

(select em.id,em.departmentid,ud.`name`

as departmentname

from

eval_marshalling em

left

join u_department ud on em.departmentid = ud.id

)m on e.marshallingid = m.id

left

join u_user u on e.administratorid = u.id

where e.administratorid is

notnull

group

by e.plateno

)emp

on ei.vehicle_merge_plate = emp.plateno

set

#車輛資訊替換

ei.veh_status = cvi.veh_status,

ei.vehicle_typeone = cvi.veh_type_one,

ei.vehicle_type = cvi.veh_type_two,

ei.tonseat_num = cvi.total_kg,

ei.plate_brand = cvi.plate_brand,

ei.engine_num = cvi.engine_num,

ei.veh_framenum = cvi.veh_framenum,

ei.veh_color = cvi.veh_color,

ei.vehicle_master = cvi.vehicle_master,

ei.mas_address = cvi.address,

#人員資訊替換

ei.worker_id_card = ww.id_card,

ei.worker_tel = ww.tel,

ei.worker_address = ww.reside_address,

ei.worker_*** = ww.***,

ei.worker_grade = ww.star_level,

#證資訊

ei.ent_jyxkztime = cvi.exam_date,

ei.mas_xkzpre = substring(cvi.trading_card,1,1),

ei.mas_xkz = substring(cvi.trading_card,3),

ei.ent_jyxkzpre = substring(cvi.ent_dlysjyxkz,1,1),

ei.ent_dlysjyxkz = substring(cvi.ent_dlysjyxkz,3),

ei.ent_busscope = cvi.bus_scope,

#企業資訊

ei.ent_code = cvi.ent_code,

ei.ent_name = cvi.ent_name,

ei.mas_address = cvi.mesaddress,

ei.ent_corporate = cvi.representative,

#執法人員

ei.zf_id = emp.administratorid,

ei.zf_dept_id = emp.departmentid,

ei.zf_dept = emp.departmentname,

ei.zf_person = emp.administratorname,

ei.zf_username = emp.username,

#修改空值狀態

ei.`status` = '未立案'

where

1=1and (ei.`status`

isnull

or ei.`status` = '未立案'

or ei.`status` = '')

and ei.infraction_time> '2017-01-01'

根據乙個表的字段,更新另外乙個表的字段

update table a set latesttm u.tm,latestdata u.data from select from table b inner join select max tm newesttm from table b group by stcd v on drp.tm v...

oracle批量更新乙個表中的乙個字段

最近遇到乙個sql問題。老大們讓我把乙個表中的一列資料做更新。更新的內容和對照表有給提供。後來仔細檢視資料 總結出這樣的sql 語句。update 更新表 b set b.需要更新的字段 select a.參考更新字段 from 對照表 a where a.對照表舊欄位 b.更新表需要更新的字段 注...

多個相同結構的表,將資料導到乙個表中

mysql中嘗試 insertinto資料庫名.表名 select from資料庫名.表名 同一伺服器 全部插入 insertintodatabaseone.dbo.userinfo select fromdatabasetwo.dbo.userinfo 主鍵或某個欄位不插入 insertintod...