mysql 使用查询子句插入数据
来源:互联网 发布:医药大数据分析 编辑:程序博客网 时间:2024/06/10 06:11
清空it_mac.goods it_mac.logistic
直接插入到运行中的库中
insert into ithelper.userInfo(phone,departmentId,userName,remark)
select distinct phone,departmentId,name asuserName,'综合' as remark
from it_mac.xingzhengas new
where not exists(
select* from ithelper.userInfo
wherephone = 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)) asgoodsId,
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.xingzhengas new
left join ithelper.userInfo as u on u.phone = new.phone
left join ithelper.goodsCategoryas 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.goodsas g
Left join itHelper.userInfoas u on u.userIndex = g.currentPersonId
- mysql 使用查询子句插入数据
- MySQL 插入&查询数据
- 使用insert子句将查询结果插入到hive表
- mysql查询后插入数据
- mysql根据查询插入数据
- MySql数据库-查询、插入数据时转义函数的使用
- 在Mysql中使用in子句查询和排序
- MySql如何插入和查询二进制数据
- mysql 创建数据库 表 插入数据 查询
- mysql的插入数据和查询
- mysql blob数据的插入与查询
- mysql嵌套查询,快速插入大量数据
- MySQL多表查询 一使用SELECT子句进行多表查询
- 使用java连接mysql数据库进行数据的查询插入更新及删除
- mysql like子句 多条件查询
- Oracle Having子句中使用子查询
- into子句中使用子查询
- 在where子句中使用子查询
- 电源管理芯片 mc13892 分析
- 组件服务中找不到office word
- 关于 arm的中断系统
- Linux 移植流水账
- Linux虚拟盘制作简易方法实践
- mysql 使用查询子句插入数据
- ASP查询ACCESS数据的常用语句
- 上月今日之今时
- Linux2.6编译记录
- wifi sleep police
- 生活随笔:你会狗眼看人低吗?
- Linux 内核启动分析
- linux2.6内核Makefile详解
- python 中的 yield