我有两个选择查询,我想从两者中选择值并有一个新查询。我试图加入他们,但我没有得到我想要的信息。
我的第一个查询是以下查询:
SELECT InWarehouse.expiry_date,
drugs.active_substance,
drugs.strength,
drugs.strength_type,
drugs.dosage_form,
drugs.minimum_quantity,
NZ(SUM(InWarehouse.quantity),0) AS quant
FROM drugs
LEFT JOIN (SELECT drug_id,
expiry_date,
SUM(in_quant - out_quant) AS quantity
FROM warehouse GROUP BY drug_id, expiry_date)
AS InWarehouse ON
InWarehouse.drug_id = drugs.id
GROUP BY InWarehouse.expiry_date,
drugs.active_substance,
drugs.strength,
drugs.strength_type,
drugs.dosage_form,
drugs.minimum_quantity;
第二个是:
SELECT InPharmacy.expiry_date,
drugs.active_substance,
drugs.strength,
drugs.strength_type,
drugs.dosage_form,
drugs.minimum_quantity,
NZ(SUM(InPharmacy.quantity), 0) as quant
FROM (drugs
LEFT JOIN (SELECT drug_id, expiry_date, SUM(in_quant - out_quant) as quantity
FROM pharmacy
GROUP BY drug_id, expiry_date) as InPharmacy
ON InPharmacy.drug_id = drugs.id)
GROUP BY InPharmacy.expiry_date,
drugs.active_substance,
drugs.strength,
drugs.strength_type,
drugs.dosage_form,
drugs.minimum_quantity;
我想得到:
InWarehouse.expiry_date,
drugs.active_substance,
drugs.strength,
drugs.strength_type,
drugs.dosage_form,
drugs.minimum_quantity,
InWarehouse.quantity + InPharmacy.quantity,
InPharmacy.expiry_date
GROUP BY InWarehouse.expiry_date = InPharmacy.expiry_date
请问有什么帮助吗?