你是什么数据库,下面给出的是sql server 2005的代码delete from tableBfrom tableB ainner join tableA b on a.keyword=b.keywordwhere a.id in (select id from tableB group by id having count(1)=1)--tableB中id只有一项 and b.num<3 --在tableA中num<3
我按照oracle的SQL写法,写了一个,如果你是sqlserver或者mysql可能不适用。select * from tableBMINUSSELECT * FROM (SELECT ID,MAX(KEYWORD) KEYWORD FROM TABLEB GROUP BY ID HAVING COUNT(*)=1) A WHERE A.KEYWORD IN (SELECT KEYWORD FROM TABLEA WHERE NUM<3)