示例:
INSERTINTOTPersonnelChange(
UserId,
DepId,
SubDepId,
PostionType,
AuthorityId,
ChangeDateS,
InsertDate,
UpdateDate,
SakuseiSyaId
)SELECT
UserId,
DepId,
SubDepId,
PostionType,
AuthorityId,
DATE_FORMAT(EmployDate,'%Y%m%d'),
NOW(),
NOW(),
1
FROM
TUserMstWHERE
`Status`=0
ANDQuitFlg=0
ANDUserId>2
扩展资料
mysql从一张表查数据并插入另一张表
INSERTINTOtable1(table1_field1,table1_field2,...)selecttable2_filed1,table2_field2,...fromtable2wherecondition1andcondition2...;
//一张表符合条件的数据插入另一张表对应字段中
insertintoshelve_goods_info(product_id,`name`,image,original_amount,amount,spec_id,spec_str,sync_time,last_updtime)selectDISTINCTproduct_id,`name`,image,original_amount,amount,spec_id,spec_str,sync_time,NOW()fromjingguo_order_goodsgroupbyproduct_idorderbysync_timedesc;
//根据一张表的数据修改另一张表的数据
updateshelve_goods_infoass,ttastsets.print_title=t.newname,s.price=t.newprice,original_price=Ceil(t.newprice*10/8)wheres.name=t.orname;