我可以在普通表的左外连接中使用sql视图吗?

ru9i0ody  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(345)

这是我的观点

CREATE OR REPLACE VIEW w AS SELECT
orp1.order_product_id,
orp1.order_id,
pov1.weight,
sum(orp1.quantity) AS 'quantity'
FROM
`order_product` orp1,
`order_option` oro1,
`product_option_value` pov1
WHERE
pov1.option_id = 6 AND oro1.product_option_value_id = pov1.product_option_value_id AND orp1.order_product_id = oro1.order_product_id
GROUP BY
orp1.order_product_id,
orp1.order_id,
pov1.weight;

这是查询部分

FROM 
    `order_product` orp6,
    `product` p,
    `product_description` pd,
    `product_to_category` p2c
LEFT OUTER JOIN w ON orp6.order_id = w.order_id AND orp6.order_product_id = w.order_product_id

但显示的错误是:
orp6.orderê是未知列

50pmv0ei

50pmv0ei1#

不要在句子中使用逗号 FROM 条款。始终使用适当的、明确的、标准的 JOIN 语法。在这个

CREATE OR REPLACE VIEW w AS
    SELECT orp1.order_product_id, orp1.order_id, pov1.weight,
            sum(orp1.quantity) AS 'quantity'
    FROM `order_product` orp1 JOIN
         `order_option` oro1
         ON orp1.order_product_id = oro1.order_product_id JOIN
         `product_option_value` pov1
         ON oro1.product_option_value_id = pov1.product_option_value_id
    WHERE pov1.option_id = 6 
    GROUP BY orp1.order_product_id, orp1.order_id, pov1.weight;

然后可以添加其他 JOIN 他在房间里 FROM 子句,例如要添加的子句。

相关问题