日期:2014-05-16 浏览次数:20473 次
1、有数据就执行更新操作,没有的话就执行插入操作
MERGE INTO score_statistics A USING (select gameid from score_statistics where gameid=82) B ON (B.gameid = A.gameid) WHEN MATCHED THEN UPDATE SET A.SCOREAVERAGE=0.8 WHEN NOT MATCHED THEN insert (GAMEID,SCOREAVERAGE,SCORENUMBER,SCORETOTAL) values (88,0.6,11,6);
2、数据库左连接
SELECT P.PROGRAMA_ID AS programaId, P.PROGRAMA_NAME AS programaName, P.PROGRAMA_HOST AS programaHost, P.PROGRAMA_DIRECTOR AS programaDirector, P.PROGRAMA_RECORDING_TIME AS programaRecordingTime, A.PROGRAMA_ATTENTION_COUNT AS programaAttentionCount, S.PROGRAMA_AVERAGE_SCORE AS programaAverageScore, R.PROGRAMA_REMIND_COUNT AS programaRemindCount FROM PROGRAMA_INFO P LEFT JOIN PROGRAMA_ATTENTION_STATISTICS A ON P.PROGRAMA_ID = A.PROGRAMA_ID LEFT JOIN PROGRAMA_SCORE_STATISTICS S ON P.PROGRAMA_ID = S.PROGRAMA_ID LEFT JOIN PROGRAMA_REMIND_STATISTICS R ON P.PROGRAMA_ID = R.PROGRAMA_ID WHERE P.PROGRAMA_ID = #value#?
?