我有6张桌子:
这些表的公共字段是项目条码,同时在此处输入sql代码:
SELECT item.*,(item.item_quantity+op.opening_stock+bom.quantitytopick+adj.adjustment_quantity) as totalquality
FROM
itemmaster item
left join openingstock op on item.item_barcode = op.item_barcode
inner join bomupload bom on op.item_barcode = bom.item_barcode
inner join adjustment_inventory adj on bom.item_barcode = adj.item_barcode
所有表项都会显示在输出中。
但是我想显示itemmaster表的所有字段和数量,如果0也基于选择查询显示的话。
答案 0 :(得分:0)
如果itemmaster表是主表,而item_barcode是在所有其他表中引用的外键,请尝试以下查询:
SELECT item.*,
(item.item_quantity + op.opening_stock + bom.quantitytopick + adj.adjustment_quantity) as totalquality
FROM
itemmaster item
LEFT JOIN openingstock op on item.item_barcode = op.item_barcode
LEFT JOIN bomupload bom on item.item_barcode = bom.item_barcode
LEFT JOIN adjustment_inventory adj on item.item_barcode = adj.item_barcode