雪地里跪求一条SQL,在线等
有表:A 字段有:(aid,aname,arole)
B 字段有:(bid, bname)
将数据插入到A中时,aid字段对应的是bid的值
不要这样的写法:insert into A(aid) select bid from B 因为A表字段都是非空的
求条SQL,在线等,新增?
[解决办法]
update aset aid=b.bidfrom a join bon a.aid=b.bid
[解决办法]
--仅以aid为例insert into a(aid)select bidfrom bwhere not exists (select 1 from a where a.aid = b.bid)--其他两个字段楼主看情况加,或者和相应表做关联添加吧!