誰かがこのクエリで私を助けてくれることを願っています. 基本的に、「結合」したいクエリが 2 つあります。最初のクエリとともに、2 番目のクエリを追加の列として使用したいと考えています。最初のものはこれです:
SELECT t_Item_Storage_Location.Storage_Loc_Nbr,
t_Storage_Location.Storage_Loc_Type_Code,
Count(t_Load.Load_Id) AS CurrentLoadCount,
t_load.MMM_Id_Nbr
FROM t_Load INNER JOIN (t_Storage_Location INNER JOIN t_Item_Storage_Location ON
t_Storage_Location.Storage_Loc_Nbr = t_Item_Storage_Location.Storage_Loc_Nbr) ON
(t_Load.Storage_Loc_Nbr = t_Item_Storage_Location.Storage_Loc_Nbr)
AND (t_Load.MMM_Id_Nbr = t_Item_Storage_Location.MMM_Id_Nbr)
where ((((t_Item_Storage_Location.MMM_Id_Nbr) Between '702004%' And '702011%')
AND ((t_Item_Storage_Location.Storage_Loc_Nbr) Like '%A')
AND ((t_Storage_Location.Storage_Loc_Type_Code)='CD')
AND ((t_Load.Active_Status_Ind)='A')
AND ((t_Load.QC_Status_Code) Like 'R%')
AND ((t_Load.MMM_Facility_Code)='MC'))
OR (((t_Item_Storage_Location.Storage_Loc_Nbr) Like '%B'))
OR (((t_Item_Storage_Location.Storage_Loc_Nbr) Like '%C'))
OR (((t_Item_Storage_Location.Storage_Loc_Nbr) Like '%D'))
OR (((t_Item_Storage_Location.Storage_Loc_Nbr) Like '%E'))
)
GROUP BY t_Item_Storage_Location.MMM_Id_Nbr,
t_Item_Storage_Location.Storage_Loc_Nbr,
t_Storage_Location.Storage_Loc_Type_Code,
t_Load.MMM_Facility_Code,
t_load.MMM_Id_Nbr
HAVING
Count(t_Load.Load_Id)<4
2 番目のものは、最初のものの t_load.MMM_Id_Nbr に基づいています。基本的に、その mmm_id_nbr を持つすべての負荷の数が必要です。
SELECT count(Load_ID) as LoadCount, MMM_Id_Nbr, storage_Loc_Nbr
FROM t_load
WHERE QC_Status_Code like 'R%' and mmm_Facility_Code ='MC' and Active_Status_Ind='A'
GROUP by MMM_Id_Nbr, storage_loc_Nbr