mysql 使用查询子句插入数据
2011-04-11 19:32
639 查看
清空
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
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
相关文章推荐
- 详解MySQL插入和查询数据的相关命令及语句使用
- 详解MySQL插入和查询数据的相关命令及语句使用
- mysql创建数据库,创建数据库表导入xlsx、txt文本,查询、删除、插入数据语句的使用
- MySQL专题5之MySQL插入数据、查询数据以及WHERE子句、UPDATE查询和DELETE语句
- MySQL中几种数据统计查询的基本使用教程
- mysql 使用存储过程分割字符串利用循环插入数据
- mysql 数据量大时插入和查询性能
- MySQL在插入90万条数据消耗的时间以及查询90万条数据时的性能优化
- MySQL的子查询中FROM和EXISTS子句的使用教程
- mysql使用函数查询树形数据
- 使用php和mysql,数据库显示插入成功,但是数据表内数据为空
- java mysql分页查询大量数据,批量插入
- mysql查询一个表的数据插入另一个表的写法
- 使用python查询MySQL数据并写入redis
- PHP使用mysql_fetch_row查询获得数据行列表的方法
- MySQL将查询结果插入到数据表中
- 使用OPENDATASOURCE 函数,在查询中实现从ACCESS获取数据,并插入SQLSERVER2000表中
- JAVA中使用JDBC插入大量mysql中的数据
- mysql使用函数查询树形数据
- 使用myeclipse插入数据到mysql 出现中文乱码|utf8乱码解决方案[适合tomcat部署的jsp应用]