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
inventory_location으로 시작하도록 From Clause를 변경하십시오.
문제
3 개의 테이블, 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 NULL NULL TOTAL
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
해결책
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
inventory_location으로 시작하도록 From Clause를 변경하십시오.