Frage

Ich habe drei Tabellen, Inventory_location, Element, item_stock

Inventory_location :

inv_loc_id (PK)
inv_loc_desc

Artikel :

item_id (PK)
code_no
item_desc
inv_cat_id

item_stock :

item_stock_id (PK)
item_id
inv_loc_id
quantity

Ich möchte einen solchen Bericht anzeigen:

Code Beschreibung LOC1 LOC2 Gesamt

1 Desc1 5 3 8

Inventory_Location hat Daten: (Loc1,Loc2,Loc3,Loc4,Loc5) & kann mit einem anderen Datensatz hinzugefügt werden.

Mein Problem ist, wenn ein Ort noch nicht in ist item_stock - bedeutet, dass noch kein Element darin gespeichert ist, es wird wie folgt angezeigt:

Code Beschreibung LOC1 LOC2 NULL NULL TOTSUM

1 Desc1 5 3 0 0 8

Was ich brauche, ist, alle Standorte anzuzeigen, auch wenn sie noch nicht in der Lage sind item_stock.

Hier ist meine Frage, hoffentlich könntest du mich korrigieren.

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 
War es hilfreich?

Lösung

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

Ändern Sie Ihre von Klausel, damit Sie mit Inventory_location beginnen.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top