这很好..
SELECT CM.CMN_CODE,CM.CMN_NAME
--(SELECT CMPI_PRCINX FROM CMD_MTRL_PRICE_INF WHERE ROWNUM = 1 ORDER BY CMPI_PRCINX DESC) as k
FROM CMN_MST CM LEFT JOIN CMD_MTRL_INF CMI ON CM.CMN_CODE=CMI.CMN_CDTY_MTRL
LEFT JOIN CMD_MTRL_PRICE_INF CMPI ON CMI.CMI_CODE = CMPI.CMI_CODE
WHERE CM.CTYP_CODE IN (SELECT CTYP_CODE FROM CTYP_MST WHERE CTYP_NAME = 'Common Material');
但这件事给我带来了麻烦。
SELECT CM.CMN_CODE,CM.CMN_NAME,
(SELECT CMPI_PRCINX FROM CMD_MTRL_PRICE_INF WHERE ROWNUM = 1 ORDER BY CMPI_PRCINX DESC) AS K
FROM CMN_MST CM LEFT JOIN CMD_MTRL_INF CMI ON CM.CMN_CODE=CMI.CMN_CDTY_MTRL
LEFT JOIN CMD_MTRL_PRICE_INF CMPI ON CMI.CMI_CODE = CMPI.CMI_CODE
WHERE CM.CTYP_CODE IN (SELECT CTYP_CODE FROM CTYP_MST WHERE CTYP_NAME = 'Common Material');
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
也尝试了
DECLARE
PCMPI_PRCINX NUMERIC;
BEGIN
SELECT CMPI_PRCINX INTO PCMPI_PRCINX FROM CMD_MTRL_PRICE_INF WHERE ROWNUM = 1 ORDER BY CMPI_PRCINX DESC;
--SELECT CMPI_PRCINX FROM CMD_MTRL_PRICE_INF WHERE ROWNUM = 1 ORDER BY CMPI_PRCINX DESC;
SELECT CM.CMN_CODE,CM.CMN_NAME
--(SELECT CMPI_PRCINX FROM CMD_MTRL_PRICE_INF WHERE ROWNUM = 1 ORDER BY CMPI_PRCINX DESC) AS K,
PCMPI_PRCINX AS PREVPRICE,
CMPI.CMPI_UPDATE_STS
FROM CMN_MST CM LEFT JOIN CMD_MTRL_INF CMI ON CM.CMN_CODE=CMI.CMN_CDTY_MTRL
LEFT JOIN CMD_MTRL_PRICE_INF CMPI ON CMI.CMI_CODE = CMPI.CMI_CODE
WHERE CM.CTYP_CODE IN (SELECT CTYP_CODE FROM CTYP_MST WHERE CTYP_NAME = 'Common Material');
END;
/
答案 0 :(得分:1)
我认为你需要重新考虑这部分问题:
,(select cmpi_prcinx
from cmd_mtrl_price_inf
where rownum = 1
order by cmpi_prcinx desc) as k
这将从cmpi_prcinx返回第一行,然后应用订单。所以它不会像你期望的那样返回cmpi_prcinx的最大值。
你可以试试这个:
,(select max(cmpi_prcinx) from cmd_mtrl_price) as k
答案 1 :(得分:0)
尝试
SELECT CM.CMN_CODE,CM.CMN_NAME,
(SELECT CMPI_PRCINX FROM CMD_MTRL_PRICE_INF WHERE ROWNUM = '1' ORDER BY CMPI_PRCINX DESC) AS K
FROM CMN_MST CM LEFT JOIN CMD_MTRL_INF CMI ON CM.CMN_CODE=CMI.CMN_CDTY_MTRL
LEFT JOIN CMD_MTRL_PRICE_INF CMPI ON CMI.CMI_CODE = CMPI.CMI_CODE
WHERE CM.CTYP_CODE IN (SELECT CTYP_CODE FROM CTYP_MST WHERE CTYP_NAME = 'Common Material');
其中ROWNUM = 1已由ROWNUM ='1'
更改答案 2 :(得分:-1)
试试这个..
SELECT CM.CMN_CODE,CM.CMN_NAME,
(SELECT TOP 1 CMPI_PRCINX FROM CMD_MTRL_PRICE_INF WHERE ROWNUM = 1 ORDER BY CMPI_PRCINX DESC) AS K
FROM CMN_MST CM LEFT JOIN CMD_MTRL_INF CMI ON CM.CMN_CODE=CMI.CMN_CDTY_MTRL
LEFT JOIN CMD_MTRL_PRICE_INF CMPI ON CMI.CMI_CODE = CMPI.CMI_CODE
WHERE CM.CTYP_CODE IN (SELECT CTYP_CODE FROM CTYP_MST WHERE CTYP_NAME = 'Common Material');