数据库两个表记录互相比较

Aa中有几条数据时bb表中没有的
SELECT count(*) count1
            FROM aa t
           WHERE  not exists
           (select 1 from bb i where i.b1 =t.b1)


Aa中有几条数据时bb表中有的
SELECT count(*) count1
            FROM aa t
           WHERE  exists
           (select 1 from bb i where i.b1 =t.b1)

猜你喜欢

转载自sanyo0714.iteye.com/blog/1629676