0

我的源代码控制数据库有 2 个表 -PRJPRJHIST,它们都具有相同的列和约束。

例如。PRJPRJHIST有以下行

PRJ TABLE    

PRJ_NAME PRJ_TYPE PRJ_VERSION PRJ_AUTHOR PRJ_LANG  
PRJ001     SCRIPT   3           MARK       PERL  
PRJ002     SCRIPT   2           JACK       KSH  
PRJ003     BINARY   4           JADE       C++  


PRJHIST TABLE  

PRJ_NAME PRJ_TYPE PRJ_VERSION PRJ_AUTHOR PRJ_LANG
PRJ001     SCRIPT   1           MARK       PERL  
PRJ001     SCRIPT   2           MARK       PERL  
PRJ001     SCRIPT   3           MARK       PERL  
PRJ002     SCRIPT   1           JACK       KSH  
PRJ002     SCRIPT   2           JACK       KSH  
PRJ003     BINARY   1           JADE       C++  
PRJ003     BINARY   2           JADE       C++  
PRJ003     BINARY   3           JADE       C++  
PRJ003     BINARY   4           JADE       C++  

PRJ表始终具有表中最大版本的PRJHIST

如何删除表max(PRJ_VERSION)中的所有行PRJHIST

即我需要从PRJHIST表 中删除以下行

PRJ001     SCRIPT   3           MARK       PERL  
PRJ002     SCRIPT   2           JACK       KSH  
PRJ003     BINARY   4           JADE       C++  
4

1 回答 1

1
DELETE FROM PRJHIST a
 WHERE EXISTS (SELECT 'X' 
                 FROM PRJ b
                WHERE a.PRJ_NAME = b.PRJ_NAME
                  AND a.PRJ_VERSION = b.PRJ_VERSION);
于 2012-12-28T04:13:36.563 回答