UPDATE CIS.NEW_QPS_PROJECT_FEE_DETAIL T
SET T.ESTIMATE_VALUE =
(SELECT NVL(SUM(T1.ESTIMATE_VALUE*T2.RATE),0)
FROM CIS.NEW_QPS_PROJECT_FEE_SUB T1 LEFT JOIN CIS.NEW_QPS_PROJECT_EXCHANGE_RATE T2 ON T1.COIN_KIND=T2.KIND
WHERE T.FEEDETAIL_PKID=T1.FEEDETAIL_PKID AND T.PROJECT_ID=T2.PROJECT_ID),
CHECK_VALUE =
(SELECT NVL(SUM(T1.CHECK_VALUE*T2.RATE),0)
FROM CIS.NEW_QPS_PROJECT_FEE_SUB T1 LEFT JOIN CIS.NEW_QPS_PROJECT_EXCHANGE_RATE T2 ON T1.COIN_KIND=T2.KIND
WHERE T.FEEDETAIL_PKID=T1.FEEDETAIL_PKID AND T.PROJECT_ID=T2.PROJECT_ID),
BUDGETARY_VALUE =
(SELECT NVL(SUM(T1.BUDGETARY_VALUE*T2.RATE),0)
FROM CIS.NEW_QPS_PROJECT_FEE_SUB T1 LEFT JOIN CIS.NEW_QPS_PROJECT_EXCHANGE_RATE T2 ON T1.COIN_KIND=T2.KIND
WHERE T.FEEDETAIL_PKID=T1.FEEDETAIL_PKID AND T.PROJECT_ID=T2.PROJECT_ID),
ESTIMATE_RELY =
(SELECT NVL(SUM(T1.ESTIMATE_RELY*T2.RATE),0)
FROM CIS.NEW_QPS_PROJECT_FEE_SUB T1 LEFT JOIN CIS.NEW_QPS_PROJECT_EXCHANGE_RATE T2 ON T1.COIN_KIND=T2.KIND
WHERE T.FEEDETAIL_PKID=T1.FEEDETAIL_PKID AND T.PROJECT_ID=T2.PROJECT_ID),
FINALLY_ESTIMATE_VALUE =
(SELECT NVL(SUM(T1.FINALLY_ESTIMATE_VALUE*T2.RATE),0)
FROM CIS.NEW_QPS_PROJECT_FEE_SUB T1 LEFT JOIN CIS.NEW_QPS_PROJECT_EXCHANGE_RATE T2 ON T1.COIN_KIND=T2.KIND
WHERE T.FEEDETAIL_PKID=T1.FEEDETAIL_PKID AND T.PROJECT_ID=T2.PROJECT_ID),
CONTRACT_VALUE =
(SELECT NVL(SUM(T1.CONTRACT_VALUE*T2.RATE),0)
FROM CIS.NEW_QPS_PROJECT_FEE_SUB T1 LEFT JOIN CIS.NEW_QPS_PROJECT_EXCHANGE_RATE T2 ON T1.COIN_KIND=T2.KIND
WHERE T.FEEDETAIL_PKID=T1.FEEDETAIL_PKID AND T.PROJECT_ID=T2.PROJECT_ID),
CHANGE_VALUE =
(SELECT NVL(SUM(T1.CHANGE_VALUE*T2.RATE),0)
FROM CIS.NEW_QPS_PROJECT_FEE_SUB T1 LEFT JOIN CIS.NEW_QPS_PROJECT_EXCHANGE_RATE T2 ON T1.COIN_KIND=T2.KIND
WHERE T.FEEDETAIL_PKID=T1.FEEDETAIL_PKID AND T.PROJECT_ID=T2.PROJECT_ID),
SETTLEMENT_VALUE =
(SELECT NVL(SUM(T1.SETTLEMENT_VALUE*T2.RATE),0)
FROM CIS.NEW_QPS_PROJECT_FEE_SUB T1 LEFT JOIN CIS.NEW_QPS_PROJECT_EXCHANGE_RATE T2 ON T1.COIN_KIND=T2.KIND
WHERE T.FEEDETAIL_PKID=T1.FEEDETAIL_PKID AND T.PROJECT_ID=T2.PROJECT_ID)
WHERE EXISTS
(SELECT 1 FROM CIS.NEW_QPS_FEECODE T1 WHERE T.FEE_ID=T1.FEE_ID AND T1.HAS_CHILD='N') And T.PROJECT_ID='0001'
看了感到怕怕,祝早日解决
头晕,发现都是取一个联合查询的最大值,你可以自定义一个函数,将最大值取出来,然后再分割字符串,取出最大值,来更新
太头痛了,这个你可以先了解这一段代码是干嘛用的,自己重构一遍,不要看现有的了,根据需求自己写!
先把所有的要更新的数据SELECT一个TABLE,之后再用TABLE与UPDATE—TABLE进行关联更新吧,感觉会高点,最少不会UPDATE每个字段就统计一次数据。
哎哟,看来我写的那些SQL语句算是小鸟了.......