Northwind查询和修改

时间:2016-01-10 16:40:45

标签: sql-server northwind

我想对Northwind数据库进行此类修改

将Chocolade添加到客户ALFKI的所有订单中,而不是 包括它

(我试图使用插入,不幸的是我失败了。)

1 个答案:

答案 0 :(得分:0)

我从这里(https://northwinddatabase.codeplex.com/)采用了数据库模式。因此,逻辑很简单:找到客户'ALFKI'的所有订单,找到巧克力productID并将所有这些信息添加到表Orders_Details

INSERT INTO Order_Details(orderID, productID, UniPrice, Quantity, Discount)
SELECT O.orderID,
       pr.productID,
       <your price>,
       <your quantity>,
       <your discount>
FROM Orders AS O, 
    (SELECT TOP 1 productID FROM Products WHERE productName like '%Chocolate%') AS pr
    JOIN Customers AS C ON O.customerID = C.customerID
WHERE C.companyName = 'ALFKI'