我有三个表,inventory_location,item,item_stock
inventory_location :
inv_loc_id (PK)
inv_loc_desc
项目:
item_id (PK)
code_no
item_desc
inv_cat_id
item_stock :
item_stock_id (PK)
item_id
inv_loc_id
quantity
我想要显示如下报告:
代码描述LOC1中Loc2总计
1 DESC1 5 3 8
inventory_location包含数据:(Loc1,Loc2,Loc3,Loc4,Loc5)
&可以添加另一条记录。
我的问题是,如果某位置尚未位于item_stock
- 意味着尚未存储任何项目,则会显示如下内容:
代码描述LOC1中Loc2空空总计
1 DESC1 5 3 0 0 8
我需要的是显示所有位置,即使它们尚未位于item_stock
。
这是我的疑问,希望你能纠正我。
SELECT
il.`inv_loc_id` AS inv_loc_id,
il.`inv_loc_desc` AS inv_loc_desc,
i.`item_id` AS item_id,
i.`nrc_no` AS nrc_no,
i.`code_no` AS code_no,
i.`item_desc` AS item_desc,
i.`unit_id` AS unit_id,
iss.`item_stock_id` AS item_stock_id,
iss.`inv_loc_id` AS inv_loc_id,
iss.`quantity` AS quantity,
i.`inv_cat_id` AS inv_cat_id
FROM `item` i
LEFT JOIN `item_stock` iss
ON iss.`item_id` = i.`item_id`
LEFT JOIN `inventory_location` AS il
ON il.`inv_loc_id` = iss.`inv_loc_id`
WHERE i.inv_cat_id = 1
GROUP BY iss.inv_loc_id,
i.item_id
ORDER BY iss.item_stock_id DESC
答案 0 :(得分:1)
FROM inventory_location il
LEFT JOIN item_stock iss ON iss.inv_loc_id = il.inv_loc_id
LEFT JOIN item i ON iss.item_id = i.item_id
更改您的FROM子句,以便从inventory_location开始。