SQL语句查处两表中,A表中的不再B表中存在的数据

来源:互联网 发布:python 遍历嵌套字典 编辑:程序博客网 时间:2024/04/30 02:05

bill_price表[数据多]

| goods_name | goods_standard | goods_maerial | goods_factoy | city_name |

sale_market表[数据多]

| goods_name | goods_standard | goods_maerial | goods_factoy | city_name |

Q:查出bill_price表中数据不再[sale_market]表中的数据 ;目的:将查处的数据写入[sale_market];

[当建立了5字段索引后,查询效率提高很多]

语句1:

select count(*) from bill_price where bill_price_id not in(select b.bill_price_id from bill_price as b, sale_market as s where s.goods_name = b.goods_name and s.goods_material = b.g;oods_material and s.goods_standard = b.goods_standard and s.goods_factory = b.goods_factory and s.city_name =b.city_name );

语句2:

select count(*) from bill_price b where  not exists (select 1 from sale_market s where s.goods_name = b.goods_name and s.goods_material = b.goods_material and s.goods_standard = b.goods_standard and s.goods_factory = b.goods_factory and s.city_name =b.city_name );

原创粉丝点击