inro sql question
We are starting to do subqueries,开发者_运维问答 and I have a bit of a toughie(for me, anyways). We have a customers table, which has an attribute of creditLimit. We have an orders table that has an ordernum, orderdate,quantity, amount. We need to increase the credit limit of a customer who has an order that exceeds their credit limit. Then, take that customer and UPDATE his credit limit plus 1000. Thanks for any help.
I'm assuming there is a primary-foreign key relationship between the Customers and Orders table.
UPDATE Customers SET Customers.creditLimit = Customers.creditLimit + 1000
WHERE EXISTS (
SELECT * FROM Orders WHERE Orders.Amount > Customers.creditLimit
AND Orders.CustomerNumber = Customers.CustomerNumber
)
精彩评论