MySQL不能找到别名

问题描述:

我有一个查询分配表...MySQL不能找到别名

select distinct(sod.sod_no), so.`so-no`, p.product_name, pod.prodstatus, po.`po-no` 
          from so_details sod 
          left join `sales-order` so on sod.so_number = so.`so-number` 
          left join products p on sod.product_id = p.product_id 
          left join po_details pod on sod.so_number = pod.so_number 
          left join `purchase-order` po on pod.po_number = po.`po-number` 
          where so.status = 'In Progress' 

但它的错误:

#1146 - Table 'po.po-no' doesn't exist 

奇怪的是,它可以读取sales-order表没有任何问题。可能是什么问题?

+1

第一次加入你为什么使用PO表? 'left join'sales-order' so so sod.so_number = so.'so-number',po.'po-no'' – Riad

+0

请注意,DISTINCT不是函数。而列标识符中包含' - '则是鲁莽的。 – Strawberry

这条线是什么?

left join `sales-order` so on sod.so_number = so.`so-number`, po.`po-no` 

我认为你可以删除, po.po-no部分。它看起来像复制粘贴错误。

问题是这一行:

left join `sales-order` so on sod.so_number = so.`so-number`, po.`po-no` 

我不知道为什么它有po.po-no。此时,您的查询仍然不知道别名po


我建议使用统一风格命名表和列。在SQL中,它通常是snake_case,但它似乎是在同一数据库中使用_-