是否可以在单个表上执行该查询?
我已经读过它可以由多个表完成(通过从第二个表中选择特定值来插入第一个表)
INSERT INTO Customers (CustomerName, Country)
SELECT SupplierName, Country FROM Suppliers
WHERE Country='Germany';
答案 0 :(得分:1)
是否可以在单个表上执行该查询?
是的,有可能:
CREATE TABLE Customers(ID INT IDENTITY(1,1),
CustomerName VARCHAR(100), Country VARCHAR(100));
INSERT INTO Customers (CustomerName, Country)
VALUES ('John', 'USA'), ('Martin','Germany');
INSERT INTO Customers (CustomerName, Country)
SELECT CustomerName, Country
FROM Customers
WHERE Country='Germany';
SELECT *
FROM Customers;
的 LiveDemo
强>
请注意,Table Spool