将数据插入数据库时出现问题。 SQL工作正常,但是创建了两个不同的行。如何合并此Statement,使其可以作为一条SQL语句运行?
INSERT INTO Transactions(CustomerId)
SELECT
CustomerId
FROM
Customers
WHERE
CustomerId = '1033';
INSERT INTO Transactions(AccountBalance)
SELECT
PlanRate
FROM
Plans
WHERE
PlanId = '11';
答案 0 :(得分:0)
应该是:
INSERT INTO Transactions(CustomerId, AccountBalance)
SELECT
Customers.CustomerId,
Plans.PlanRate
FROM
Customers
JOIN Plans ON
[JOIN CONDITION HERE]
WHERE
[WHERE CONDITION HERE];
重点是您需要在一个查询中选择两列。