求两条sql语句...

来源:百度知道 编辑:UC知道 时间:2024/05/19 04:22:41
两个表结构一模一样如下:

A表 LoverA B表loverB

两表字段相同:id int
phone varchar
time datetime
is_valid bit

两个表的数据不同,如LOVERA 有100条记录 LOVERB有200条记录

用一条sql语句 根据phone 列出两个表不相同的记录集合

用一条sql语句 根据phone 统计两个表的不相同的记录集的总数

select * from LOVERA where phone not in(select phone from LOVERB) union select * from LOVERB where phone not in(select phone from LOVERA)
这语句能列出两表不同的条目,但想了很久也想不到怎样才能分别列出两张表不同的条目,我的思路是分别在两表中查出不同的条目 即(A表有B表没有和B表有A表没有两语句),然后用union将两结果结合起来!
下一句是:
select 它们不同的条目个数分别为=count(*) from LOVERA where phone not in(select phone from LOVERB) union select count(*) from LOVERB where phone not in(select phone from LOVERA)
第二句也是差不多的情况,但这是不同的记录数,所以只有两个数据,这样就不难区分了!
楼主如果想到了解决办法也请告知一下我,大家共同学习!