mysql 查询语言 一张表的数据插入另一张表的sql语句

mysql 查询语言 一张表的数据插入另一张表的sql语句,第1张

示例:

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

你好,很高兴回答你的问题。

我理解你的这个需求可以用下面的语句实现。

insert into table_a (m) select 'efg' as m from table_a where m='abc'

其他字段自行补一下。

如果主键不是自增的话,还需要考虑下主键值。

如果有帮助到你,请点击采纳。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11628332.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存