选择一个值时查询乘以结果
Query Multiplies The Result When Selecting For One Value
您好,我想显示产品、子材料、替代品、订单和日期。产品有 5 个子物料和 8 个不同日期的订单。我面临的问题是 Sub Materials 根据顺序乘以 8 倍。如何为一个重复值正确获取数据?感谢您的支持。
-查询如下
SELECT
B.BOMREC_CODE AS PRODUCT_CODE,
S.NAME AS PRODUCT_NAME,
B.BOMREC_MATERIALCODE AS SUB_MATERIAL,
S1.NAME AS SUB_MATERIAL_NAME,
B.BOMREC_ALTCODE AS ALTERNATIVE,
(SIP.SF_QUANTITY - SIP.SF_NEWSHIPPED) AS OPEN_ORDERQT
SIP.DLVDATE AS DELIERY_DATE
FROM BOMU01T B
LEFT JOIN STOCK00 S ON TRIM(S.CODE)=TRIM(B.BOMREC_CODE)
LEFT JOIN STOCK00 S1 ON TRIM(S1.CODE)=TRIM(B.BOMREC_MATERIALCODE)
LEFT JOIN STOCK40T SIP ON TRIM(SIP.CODE)=TRIM(B.BOMREC_CODE)
WHERE B.BOMREC_CODE='2496802300'
ORDER BY 1 DESC
-STOCK00 Table 包含产品名称
-STOCK40T Table 持有订单。当我搜索“2496802300”的订单时,它显示如下
-我想要的应该是这样的
您似乎缺少 Group by 子句
试试这个:
SELECT
B.BOMREC_CODE AS PRODUCT_CODE,
S.NAME AS PRODUCT_NAME,
B.BOMREC_MATERIALCODE AS SUB_MATERIAL,
S.NAME AS SUB_MATERIAL_NAME,
B.BOMREC_ALTCODE AS ALTERNATIVE,
(SIP.SF_QUANTITY - SIP.SF_NEWSHIPPED) AS OPEN_ORDERQT
SIP.DLVDATE AS DELIERY_DATE
FROM BOMU01T B
LEFT JOIN STOCK00 S ON TRIM(B.BOMREC_CODE)= TRIM(S.CODE)
AND TRIM(B.BOMREC_MATERIALCODE)=TRIM(S.CODE)
LEFT JOIN STOCK40T SIP ON TRIM(B.BOMREC_CODE)=TRIM(SIP.CODE)
WHERE B.BOMREC_CODE='2496802300'
ORDER BY 7 DESC;
您好,我想显示产品、子材料、替代品、订单和日期。产品有 5 个子物料和 8 个不同日期的订单。我面临的问题是 Sub Materials 根据顺序乘以 8 倍。如何为一个重复值正确获取数据?感谢您的支持。
-查询如下
SELECT
B.BOMREC_CODE AS PRODUCT_CODE,
S.NAME AS PRODUCT_NAME,
B.BOMREC_MATERIALCODE AS SUB_MATERIAL,
S1.NAME AS SUB_MATERIAL_NAME,
B.BOMREC_ALTCODE AS ALTERNATIVE,
(SIP.SF_QUANTITY - SIP.SF_NEWSHIPPED) AS OPEN_ORDERQT
SIP.DLVDATE AS DELIERY_DATE
FROM BOMU01T B
LEFT JOIN STOCK00 S ON TRIM(S.CODE)=TRIM(B.BOMREC_CODE)
LEFT JOIN STOCK00 S1 ON TRIM(S1.CODE)=TRIM(B.BOMREC_MATERIALCODE)
LEFT JOIN STOCK40T SIP ON TRIM(SIP.CODE)=TRIM(B.BOMREC_CODE)
WHERE B.BOMREC_CODE='2496802300'
ORDER BY 1 DESC
-STOCK00 Table 包含产品名称
-STOCK40T Table 持有订单。当我搜索“2496802300”的订单时,它显示如下
-我想要的应该是这样的
您似乎缺少 Group by 子句
试试这个:
SELECT
B.BOMREC_CODE AS PRODUCT_CODE,
S.NAME AS PRODUCT_NAME,
B.BOMREC_MATERIALCODE AS SUB_MATERIAL,
S.NAME AS SUB_MATERIAL_NAME,
B.BOMREC_ALTCODE AS ALTERNATIVE,
(SIP.SF_QUANTITY - SIP.SF_NEWSHIPPED) AS OPEN_ORDERQT
SIP.DLVDATE AS DELIERY_DATE
FROM BOMU01T B
LEFT JOIN STOCK00 S ON TRIM(B.BOMREC_CODE)= TRIM(S.CODE)
AND TRIM(B.BOMREC_MATERIALCODE)=TRIM(S.CODE)
LEFT JOIN STOCK40T SIP ON TRIM(B.BOMREC_CODE)=TRIM(SIP.CODE)
WHERE B.BOMREC_CODE='2496802300'
ORDER BY 7 DESC;