我再次来找你寻求进一步的帮助:)我已经达到了这样的程度,我可以加入两个查询,生成具有不同值的重复列,但是我仍然面临整个查询产生许多每个大小的结果(文字和技术是1:1)我怎样才能生成一个只为每个大小显示一次每种材料的查询?在此先感谢并感谢您的所有帮助:
SELECT *
FROM
(SELECT P.PLANT_CODE,
P.STOCK_CATEGORY,
P.MATERIAL,
P.DISTRIBUTION_VERSION_CODE,
P.PERIOD_CODE,
P.REQUIREMENTS_DATE,
P.PLANNED_QTY AS 'REM PLAN QTY',
P.VERSION_IND_FLAG,
P.SIZE_LITERAL,
P.WITHDRAWN_QUANTITY,
P.TECHNICAL_INDEX,
P.PLANNED_QTY + P.WITHDRAWN_QUANTITY AS 'ORIGINAL FCST QTY'
FROM VW_PLANNED_REQMNTS_TXT P
WHERE P.PLANT_CODE IN ('6040','6041')
AND P.STOCK_CATEGORY IN ('A60385000','A60385003')
AND P.DISTRIBUTION_VERSION_CODE IN ('00','01','ZU','Z2')
AND P.REQUIREMENTS_DATE < GETDATE() - 59
AND P.PLANNED_QTY > 0) AS P1
JOIN
(SELECT
SUM(P.PLANNED_QTY) AS 'FUTURE_FCST',
P.MATERIAL,
P.TECHNICAL_INDEX,
P.SIZE_LITERAL
FROM VW_PLANNED_REQMNTS_TXT P
WHERE P.REQUIREMENTS_DATE > GETDATE()
AND P.PLANNED_QTY > 0
GROUP BY P.PLANNED_QTY,
P.MATERIAL,
P.TECHNICAL_INDEX,
P.SIZE_LITERAL) AS P2
ON P1.MATERIAL = P2.MATERIAL
AND P1.TECHNICAL_INDEX = P2.TECHNICAL_INDEX`
ORDER BY P1.MATERIAL,
P1.TECHNICAL_INDEX;