在以下查询中,错误 Unknown column 'order.id' in 'on clause'
是由我在 INNER JOIN 中的 order.id 引用引发的。 id
列确实存在。
知道为什么它不能通过子查询访问吗?
SELECT
SUM(price+shipping_price) AS total_sales,
COUNT(id) AS total_orders,
AVG(price+shipping_price) AS order_total_average,
(SELECT
SUM(quantity)
FROM `order_product`
WHERE `order`.id = order_product.order_id
) as total_units,
SUM(price+shipping_price)/7 as daily_average,
(SELECT
SUM(order_product.price * order_return_product.quantity)
FROM order_return_product
INNER JOIN order_product ON (
order_product.order_id = `order`.id AND
order_product.product_id = order_return_product.product_id AND
order_product.vehicle_id = order_return_product.vehicle_id
)
WHERE return_id IN (
SELECT
id
FROM order_return
WHERE status_id != 3 AND
order_return.order_id = `order`.id
)
) as total_returns
FROM `order`
WHERE created >= 1278388801 AND
created <= 1279079999 AND
fraud = 0 AND
type_id = 4
当我注释掉 INNER JOIN 中的 order
.id 时,我没有收到任何错误
最佳答案
order
.id 超出此查询的范围 - 您只处理子查询中的 order_return_product
和 order_product
表.
关于sql - SQL `order` .id 未知列中的变量范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3237499/