有没有办法可以使用硬值和子查询的组合来插入一个命令的表?
例如:
INSERT INTO suppliers (supplier_id, supplier_name, supplier_type)
SELECT account_no, name
FROM customers
WHERE city = 'San Diego';
Run Code Online (Sandbox Code Playgroud)
我需要supplier_type为3.所以我可以为第二行执行以下操作吗?
SELECT account_no, name, supplier_type = 3
Run Code Online (Sandbox Code Playgroud)
supplier_type不在customers表中
Ker*_*mit 17
只需将其添加到您的SELECT字段中即可
INSERT INTO suppliers (supplier_id, supplier_name, supplier_type)
SELECT account_no, name, 3 AS supplier_type
FROM customers
WHERE city = 'San Diego';
Run Code Online (Sandbox Code Playgroud)