SQL語句查處兩表中,A表中的不再B表中存在的資料

2021-06-02 20:46:47 字數 923 閱讀 1598

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 );

使用SQL語句操作表和表中的資料

一 分類 1 drop table 表名稱 drop 刪除表 刪除內容和定義,釋放空間。簡單來說就是把整個表去掉.以後要新增資料是不可能的,除非新增乙個表。drop語句將刪除表的結構被依賴的約束 constrain 觸發器 trigger 索引 index 依賴於該錶的儲存過程 函式將被保留,但其狀...

sql中建庫建表的sql語句

建庫 use master goif exists select from sysdatabases where name news drop database news gocreate database news on primary name news filename f dbproject...

sql中為表加約束的sql語句

sql中為表加約束的sql語句收藏 為表userinfo的loginname列加唯一約束 alter table userinfo add constraint uq loginname unique loginname 為表userinfo的loginname列加主鍵約束 alter table ...