表A 结构如下 撤销部门 cancel_dept cancel_person 撤销人
表B用户表 结构如下 UserName,DeptId
其中 cancel_person 对应UserName 字段唯一.
现表A cancel_dept 这个字段有点问题,部分数据为空.
现在要求 按照表A cancel_person 查询出 DeptId
然后更新表A的cancel_dept 字段.大概意思就是 update A set cancel_dept=?
表B用户表 结构如下 UserName,DeptId
其中 cancel_person 对应UserName 字段唯一.
现表A cancel_dept 这个字段有点问题,部分数据为空.
现在要求 按照表A cancel_person 查询出 DeptId
然后更新表A的cancel_dept 字段.大概意思就是 update A set cancel_dept=?
所以 还要再 加上 where exists (select 1 from b where a.cancel_person=b.UserName);
where cancel_person in (selectdistinct DeptId from a)
这个条件不对吧.应该是
update A set cancel_dept= (select DeptIdfrom bwhere UserName= a.cancel_person)
where A.cancel_dept is null