由于子查询返回行和列,因此您可以针对子查询加入,就像您可以加入普通表一样。
SELECT
P.ProductCode, I.QuantityInStock as Qty, P.Title, P.Price
FROM
Products as P
JOIN
(SELECT * FROM Inventory) as I on (P.ProductCode = I.ProductCode);
你怎么能重写这个查询,所以它不使用子查询?
我正在尝试重写但不确定是否正确
SELECT P.ProductCode, I.QuantityInStock as Qty, P.Title, P.Price
FROM Products as P
WHERE Inventory as I on (P.ProductCode = I.ProductCode);
这是对的吗?
答案 0 :(得分:0)
SELECT P.ProductCode, I.QuantityInStock as Qty, P.Title, P.Price
FROM Products as P
JOIN Inventory as I on P.ProductCode = I.ProductCode;
答案 1 :(得分:0)
由于您从库存中选择了所有列,您可以执行
SELECT
P.ProductCode, I.QuantityInStock as Qty, P.Title, P.Price
FROM
Products as P
JOIN
Inventory I on P.ProductCode = I.ProductCode;
答案 2 :(得分:0)
SELECT P.ProductCode, I.QuantityInStock as Qty, P.Title, P.Price
FROM Products as P, Inventory as I
WHERE P.ProductCode = I.ProductCode