我想从表inv_site_item
中的'item_id' in inv_sie_item = 'item_code'
中的inv_items
中获取转移的物品总数,我也从打包表中获取了打包内容,在此查询中,只有inv_site_item
存在问题,打包表才能正常工作。
错误是:Unknown column 'inv_site_item.site_id' in 'field list'
$where .= " AND inv_items.item_code = $item_code";
$query = "SELECT inv_items.*,packing.name_en `packing_name`,"
. " COUNT(inv_site_item.site_id) `transfer_out`, COUNT(inv_site_item.location_site_id) `transfer_in` FROM inv_items"
. " left join "
. "inv_packing as packing on packing.id=inv_items.packing"
. " left join "
. "inv_site_item as transfer on transfer.item_id=inv_items.item_code"
. " WHERE item_code !='' " . $where . "";
最佳答案
您必须改用表别名transfer
,所以:
从
inv_site_item.site_id
至
transfer.site_id
也将
inv_site_item.location_site_id
设置为transfer.location_site_id
关于php - sql左联接不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35622635/