mysql 使用查询子句插入数据

清空 it_mac.goods it_mac.logistic

 

直接插入到运行中的库中

insert into ithelper.userInfo (phone,departmentId,userName,remark)

 

select distinct phone,departmentId,name as userName,' 综合 ' as remark

from it_mac.xingzheng as new

 

where not exists(

         select * from ithelper.userInfo

         where phone = new.phone

);

 

 

增加货物信息 goods

其中 goodsId categoryId setting mac currentPersonId indexOfBatch 需要根据 new 表中的填

 

goodsId goodsCategory flag ,日期为当前日期,批号为 Z ,货物号为累加

 

 

SET @NUM=0;

SET @GOODSID =date_format ( now ( ) , '%Y%m%d' );

Insert into it_mac.goods (goodsId,providerId,departmentId,categoryId,setting,location,mac,state,remark,

                            currentPersonId,batchId,indexOfBatch)

 

select

CONCAT(c.flag,@GOODSID, 'Z', right (concat('0000', @NUM+1),3)) as goodsId,

2 as providerId,

new.departmentId,

new.categoryId,

new.setting,

'IT 仓库 ' as location,

new.mac,

1 as state,

new.remark,

u.userIndex as currentPersonId,

26 as batchId,

@NUM:=@NUM+1 as indexOfBatch

 

from it_mac.xingzheng as new

left join  ithelper.userInfo as u on  u.phone = new.phone

left join ithelper.goodsCategory as c on  c.categoryId = new.categoryId

 

 

 

 

添加 logistic 记录

Insert into itHelper.logistic (goodsId,userIndex,time,departmentId,state,remark)

Select g.goodsId,u.userIndex,now() as time,u.departmentId,g.state,g.remark  

from it_mac.goods as g

Left join itHelper.userInfo as u on u.userIndex = g.currentPersonId

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值