删除具有联合主键的记录

DELETE t1 FROM `datatower-all`.DWD_COM_TEAM_TRAINING_RF t1
LEFT JOIN `datatower-all`.`TMP_DWD_COM_TEAM_TRAINING_RF` t2
ON t1.POI_ID=t2.POI_ID AND t1.TRAINING_RF_ID=t2.TRAINING_RF_ID (POI_ID与TRAINING_RF_ID均为表DWD_COM_TEAM_TRAINING_RF的主键)
WHERE t2.POI_ID IS NULL AND t1.POI_ID IN
(SELECT t3.POI_ID FROM `datatower-all`.DWD_POI t3 WHERE t3.SOURCE_SYS IN (SELECT SOURCE_SYSTEM_ID FROM `datatower-all`.TOOLS_ETL_SOURCE_SYSTEM))
若报错:unknown table t1 in multi delete,则在第一行第一个t1前加上数据库,变成`datatower-all`.t1。如果加了所在数据库为前缀报同样的错误的话就把前缀去掉,
只写t1。

posted @ 2017-03-15 17:09  NA-CODE  阅读(752)  评论(0编辑  收藏  举报