在子查询中,我希望能够在 WHERE 子句中添加:
duedate<=quotehed.duedate
quotehed.duedate 在主查询中。我不知道如何将 quotehed.duedate 带入子查询,因为它与我的子查询不在同一个表中。我也不知道如何确保 quotehed.duedate 将从参数中选择的报价单中提取截止日期@p_quotenum
。
我的整个查询如下。我非常感谢任何帮助!谢谢!
SELECT partwhse.warehousecode,
partwhse.allocqty,
partwhse.onhandqty,
quotehed.quotenum,
quotehed.custnum,
quotehed.datequoted,
quotehed.duedate,
quotedtl.quoteline,
quotedtl.partnum,
quotedtl.reqshipdate,
quotedtl.sellingexpectedqty,
plantwhse.plant,
part.partdescription,
t_partdtl1.totaldemand
FROM part
INNER JOIN quotedtl
ON part.company = quotedtl.company
AND part.partnum = quotedtl.partnum
LEFT OUTER JOIN (SELECT company,
partnum,
requirementflag,
SUM(quantity) AS totaldemand,
plant,
duedate
FROM partdtl AS partdtl_1
WHERE ( company = 'lot' )
AND ( requirementflag = '1' )
AND ( plant = @p_plant )
GROUP BY company,
partnum,
requirementflag,
plant,
duedate) AS t_partdtl1
ON quotedtl.company = t_partdtl1.company
AND quotedtl.partnum = t_partdtl1.partnum
LEFT OUTER JOIN partwhse
INNER JOIN plantwhse
ON partwhse.company = plantwhse.company
AND partwhse.partnum = plantwhse.partnum
AND partwhse.warehousecode = plantwhse.warehousecode
ON quotedtl.company = plantwhse.company
AND quotedtl.partnum = plantwhse.partnum
RIGHT OUTER JOIN quotehed
ON quotedtl.company = quotehed.company
AND quotedtl.quotenum = quotehed.quotenum
WHERE ( quotehed.quotenum = @p_quotenum )
AND ( quotehed.company = 'lot' )
AND ( plantwhse.plant = @p_plant )
ORDER BY quotehed.quotenum,
quotedtl.quoteline