求Oracle语句-谢谢
1.根据表AA中【OYA_BI】和【BI】 列关联更新列【OYA_NAME】的值
UPDATE AA SET OYA_NAME=
(SELECT DISTINCT A.NAME FROM AA A WHERE RTRIM(OYA_BI)=RTRIM(A.BI) )
不起作用,执行完,NAME列都为空,而实际上OYA_BI和BI能关联到数
-------------------
BI NAME OYA_BI OYA_NAME
SS BING CC
CC ABCD DD
关联结果:
BI NAME OYA_BI OYA_NAME
SS BING CC ABCD
--------------------
2. 将表AA中按KATAMEI,EDP_SKKR_SYK 分组KOTEI_FLOW_RNBN值最大的【ZB】列复制1。
UPDATE AA SET ZB='1'
FROM AA A,
( SELECT KATAMEI,EDP_SKKR_SYK ,MAX(KOTEI_FLOW_RNBN)KOTEI_FLOW_RNBN FROM ALPSSHU2
GROUP BY KATAMEI,EDP_SKKR_SYK ORDER BY KATAMEI, EDP_SKKR_SYK)B
WHERE A.KATAMEI=B.KATAMEI AND A.KOTEI_FLOW_RNBN=B.KOTEI_FLOW_RNBN AND A.EDP_SKKR_SYK=B.EDP_SKKR_SYK
怎么转化为ORACLE ,写不出来。
谢谢各位大侠。
------解决方案--------------------第一个:
MERGE INTO AA T1 USING AA T2 ON(T1.OYA_BI=T2.BI) WHEN MATCHED THEN UPDATE SET T1.OYA_NAME=T2.NAME;
第二个语句你可以仿照这个
------解决方案--------------------第一个你把所有的列名前加上别名试试?公司没练习的server,不好测。
------解决方案--------------------UPDATE AA A1
SET OYA_NAME =
(SELECT DISTINCT A.NAME
FROM AA A2
WHERE RTRIM(A2.OYA_BI) = RTRIM(A1.BI))
UPDATE AA A
SET ZB = '1'
where exists (select 1
from (SELECT KATAMEI,
EDP_SKKR_SYK,
MAX(KOTEI_FLOW_RNBN) KOTEI_FLOW_RNBN
FROM ALPSSHU2
GROUP BY KATAMEI, EDP_SKKR_SYK
ORDER BY KATAMEI, EDP_SKKR_SYK) B
WHERE A.KATAMEI = B.KATAMEI
AND A.KOTEI_FLOW_RNBN = B.KOTEI_FLOW_RNBN
AND A.EDP_SKKR_SYK = B.EDP_SKKR_SYK)