问题描述
我有一个包含一些数据的临时表 (products_temp),我还有另一个表(产品)需要插入数据.我需要在新记录上手动设置一些常量,例如 vendor_id=1 等...
I have a temporary table (products_temp) with some data, and I have another table (products) I need to insert the data into. I have some constants I need to set manually on new records, like vendor_id=1, etc...
是否可以在一个请求中插入临时表数据和常量?
Is it possible to do the insertion with the temporary table data and the constants in one request?
temp_products:
temp_products:
product_name | product_desc | category_name | mf_name ...
产品(category_name,mf_name 不在):
products (category_name, mf_name is not in):
product_id | product_name | product_desc | vendor_id | distributor_id ...
常量:
vendor_id=1, distributor_id=2
推荐答案
使用 INSERT ... SELECT 语句,您在其中选择常量值以及来自 products_temp 的数据:
Use an INSERT ... SELECT statement where you are selecting constant values as well as data from products_temp:
INSERT INTO products (product_data, vendor_id)
SELECT data, '1' FROM products_temp
这篇关于MySQL - 从与常量合并的另一个表中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)