1054-“ where子句”中的未知列“ iaiirq.assignedRQQty”

时间:2019-11-03 20:33:40

标签: mysql

SELECT  iaiirq.requisition_id, SUM(iaiirq.quantity) as assignedRQQty, iaipo.requisition_id, 
iaipo.assignedPOQty FROM inv_assign_item_to_inv_requisition as iaiirq
LEFT JOIN (SELECT requisition_id, SUM(purchase_order_quantity) as assignedPOQty from  
inv_assign_item_to_purchase_order GROUP BY requisition_id ) as iaipo on iaiirq.requisition_id = 
iaipo.requisition_id
WHERE  iaiirq.assignedRQQty > iaipo.assignedPOQty 
GROUP BY iaiirq.requisition_id

产生这样的错误,

1054-“ where子句”中的未知列“ iaiirq.assignedRQQty”

1 个答案:

答案 0 :(得分:1)

错误消息说表中不存在iaiirq.assignedRQQty,因为您在select子句中定义了它,而不是像下面那样使用HAVING。

SELECT  iaiirq.requisition_id, SUM(iaiirq.quantity) as assignedRQQty, iaipo.requisition_id, 
iaipo.assignedPOQty FROM inv_assign_item_to_inv_requisition as iaiirq
LEFT JOIN (SELECT requisition_id, SUM(purchase_order_quantity) as assignedPOQty from  
inv_assign_item_to_purchase_order GROUP BY requisition_id ) as iaipo on iaiirq.requisition_id = 
iaipo.requisition_id
GROUP BY iaiirq.requisition_id
HAVING assignedRQQty > iaipo.assignedPOQty