Oracle查询:
MERGE into CMDASHBOARD x using
(
SELECT
COUNT(C.CMHBASEROWKEYID_PK) count ,
c.CLUSTERID_FK ,
c.BAND
FROM CMHBASEROWKEY C
WHERE (C.SICOUNT+C.NSICOUNT) = 0
AND C.HIERARCHY = 'CELL'
AND TRUNC(C.MODIFIEDTIME) = TRUNC(sysdate)
AND C.SITETYPE != 'SMALL_CELL'
GROUP by c.CLUSTERID_FK , c.BAND
) y on( x.CLUSTERID_FK = y.CLUSTERID_FK and x.BAND=y.band )
when matched then UPDATE set x.SECTORCOMPLIANTCOUNT = y.count
WHERE TRUNC(x.CREATEDDATE) = TRUNC(sysdate);
我试过这个:
insert into CMDASHBOARD (SECTORCOMPLIANTCOUNT)
select COUNT(s.CMHBASEROWKEYID_PK) count, s.CLUSTERID_FK, s.BAND
from CMHBASEROWKEY s
JOIN CMDASHBOARD p ON p.CLUSTERID_FK= s.CLUSTERID_FK and p.BAND=s.band
where (s.SICOUNT+s.NSICOUNT)=0
AND s.HIERARCHY ='CELL'
AND s.SITETYPE != 'SMALL_CELL'
AND s.MODIFIEDTIME=sysdate()
GROUP by s.CLUSTERID_FK ,s.BAND;
ON DUPLICATE KEY UPDATE SECTORCOMPLIANTCOUNT= summ;