新人实用型数据修改sql语句,收藏准没错!!
新人进公司如果需要处理数据,经常会遇到这样的问题:
自己拿到的数据只有名称没有Id,我们需要找到当前数据表,找到组织架构表,记录组织名称和组织Id。
以下sql中ecc_infolist为数据表,user_structure 为组织架构表
type代表科室还是小组
update ecc_infolist t set t.Office_Id =
(select id from user_structure t1 where t1.`TYPE` ='office_name' and t.office_id = t1.NAME)
where exists
(select 1 from user_structure t2 where t2.NAME = t.Office_Id)
;