Question

J'ai trois tables, Inventory_location, item, item_stock

Inventory_location :

inv_loc_id (PK)
inv_loc_desc

Objet :

item_id (PK)
code_no
item_desc
inv_cat_id

item_stock :

item_stock_id (PK)
item_id
inv_loc_id
quantity

Je veux afficher un rapport comme celui-ci:

Description du code loc1 loc2 total

1 DESC1 5 3 8

Inventory_location a des données: (Loc1,Loc2,Loc3,Loc4,Loc5) & peut être ajouté avec un autre enregistrement.

Mon problème est que si un emplacement n'est pas encore item_stock - ce qui signifie qu'aucun élément, il y a encore stocké, il s'affichera comme ce qui suit:

DESCRIPTION DE CODE LOC1 LOC2 NULL NULL TOTAL

1 DESC1 5 3 0 0 8

Ce dont j'ai besoin, c'est d'afficher tous les emplacements même s'ils ne sont pas encore item_stock.

Voici ma requête, j'espère que vous pourriez me corriger.

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 
Était-ce utile?

La solution

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

Changez votre clause de votre clause pour commencer par Inventory_Location.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top