SELECT IT_TransContractor.ModelID, IT_EquipModel.Model_Desc, Sum(IT_TransContractor.ReceivedQty) AS Qty, Sum(IT_TransStaff.WithdrawalQty) AS RecQty
FROM IT_EquipModel INNER JOIN (IT_Description INNER JOIN (IT_TransContractor INNER JOIN IT_TransStaff ON (IT_TransContractor.ItemNo = IT_TransStaff.ItemNo) AND (IT_TransContractor.ModelID = IT_TransStaff.ModelID)) ON IT_Description.ItemNo = IT_TransStaff.ItemNo) ON (IT_EquipModel.ModelID = IT_TransContractor.ModelID) AND (IT_EquipModel.OrderedTimes = IT_TransContractor.OrderedTimes) AND (IT_EquipModel.ContractorID = IT_TransContractor.ContractorID) AND (IT_EquipModel.ItemNo = IT_TransContractor.ItemNo)
WHERE (((IT_TransContractor.ItemNo)='IT002'))
GROUP BY IT_TransContractor.ModelID, IT_EquipModel.Model_Desc, IT_TransContractor.ItemNo, IT_Description.Item_Desc;
T^Tนั่งปวดหลายวันแหละครับหาไม่เจอสักที
Tag : .NET, Ms Access, MySQL, Win (Windows App), VS 2010 (.NET 4.x)
SELECT IT_TransContractor.ModelID, IT_EquipModel.Model_Desc, Sum(IT_TransContractor.ReceivedQty) AS Qty, Sum(IT_TransStaff.WithdrawalQty) AS RecQty
FROM IT_Description LEFT JOIN (IT_EquipModel LEFT JOIN (IT_TransContractor LEFT JOIN IT_TransStaff ON (IT_TransContractor.ItemNo = IT_TransStaff.ItemNo) AND (IT_TransContractor.ModelID = IT_TransStaff.ModelID)) ON (IT_EquipModel.ModelID = IT_TransContractor.ModelID) AND (IT_EquipModel.OrderedTimes = IT_TransContractor.OrderedTimes) AND (IT_EquipModel.ContractorID = IT_TransContractor.ContractorID) AND (IT_EquipModel.ItemNo = IT_TransContractor.ItemNo)) ON IT_Description.ItemNo = IT_EquipModel.ItemNo
WHERE (((IT_TransContractor.ItemNo)='IT002'))
GROUP BY IT_TransContractor.ModelID, IT_EquipModel.Model_Desc, IT_TransContractor.ItemNo, IT_Description.Item_Desc;
SELECT IT_TransContractor.ModelID, IT_EquipModel.Model_Desc, Sum(IT_TransContractor.ReceivedQty) AS Qty, Sum(IT_TransStaff.WithdrawalQty) AS RecQty
FROM (IT_Description INNER JOIN IT_EquipModel ON IT_Description.ItemNo = IT_EquipModel.ItemNo) INNER JOIN (IT_TransContractor INNER JOIN IT_TransStaff ON IT_TransContractor.ModelID = IT_TransStaff.ModelID) ON IT_EquipModel.ModelID = IT_TransContractor.ModelID
WHERE (((IT_TransContractor.ItemNo)='IT002'))
GROUP BY IT_TransContractor.ModelID, IT_EquipModel.Model_Desc, IT_TransContractor.ItemNo, IT_Description.Item_Desc;
SELECT IT_EquipModel.ItemNo, IT_EquipModel.ModelID, IT_EquipModel.Model_Desc, (SELECT Sum(Switch([IT_TransContractor.ReceivedQty] Is Null,0,[IT_TransContractor.ReceivedQty] Is Not Null,[IT_TransContractor.ReceivedQty])) AS Qty
FROM IT_TransContractor where ( IT_EquipModel.ModelID = IT_TransContractor.ModelID)) AS Qty,
(SELECT Sum(IT_TransStaff.WithdrawalQty) AS RecQty FROM IT_TransStaff
where ( IT_EquipModel.ModelID = IT_TransStaff.ModelID) ) AS RecQty , [Qty] - [RecQty] as AwQty
FROM IT_EquipModel
WHERE (((IT_EquipModel.ItemNo)='IT002'))
GROUP BY IT_EquipModel.ItemNo, IT_EquipModel.ModelID, IT_EquipModel.Model_Desc