當前位置:首頁 » 編程語言 » sqlnotinexcept

sqlnotinexcept

發布時間: 2024-05-20 02:53:10

A. sql not in 兩個表找不同的問題 100分在線等……

SQLSERVER版本:

select * from t1 t where t.a1 in(
select a1 from t1 except select a1 from t2 )

附上我的測試sql:
create table #1(a1 varchar(10),a2 nvarchar(10),a3 varchar(10));
create table #2(a1 varchar(10),a2 nvarchar(10),a3 varchar(10));
insert into #1( a1,a2,a3)values('01','張三','90'),('02','李四','85'),('03','王五','89');
insert into #2( a1,a2,a3)values('01','張三','98'),('04','謝六','88'),('05','陳四','87');
select * from #1 t where t.a1 in(
select a1 from #1 except select a1 from #2 )
drop table #1;
drop table #2;

ORACLE版本:

select * from t1 t where t.a1 in(
select a1 from t1 minus select a1 from t2 );

附上測試sql:

create table t1(a1 varchar(10),a2 nvarchar2(10),a3 varchar(10));
create table t2(a1 varchar(10),a2 nvarchar2(10),a3 varchar(10));
insert into t1( a1,a2,a3) select * from (
select '01' a1 ,'張三' a2,'90' a3 from al
union
select '02' a1 ,'李四' a2,'85' a3 from al
union
select '03' a1 ,'李四' a2,'89' a3 from al);
insert into t2( a1,a2,a3) select * from (
select '01' a1 ,'張三' a2,'98' a3 from al
union
select '04' a1 ,'謝六' a2,'88' a3 from al
union
select '05' a1 ,'陳四' a2,'87' a3 from al);
select * from t1 t where t.a1 in(
select a1 from t1 minus select a1 from t2 );
drop table t1;
drop table t2;

熱點內容
稅盤密碼忘了去改需要帶什麼 發布:2024-11-27 15:41:10 瀏覽:276
拉筋要加密 發布:2024-11-27 15:38:51 瀏覽:323
電腦當伺服器怎麼降低功耗 發布:2024-11-27 15:30:45 瀏覽:641
蘋果手機誇克緩存的視頻怎麼轉為本地視頻 發布:2024-11-27 15:24:05 瀏覽:810
linuxm4 發布:2024-11-27 15:15:12 瀏覽:321
演算法交易現狀 發布:2024-11-27 15:05:49 瀏覽:825
搜同網伺服器為什麼登錄不上 發布:2024-11-27 15:05:41 瀏覽:287
如何讓無線網速變快華為安卓手機 發布:2024-11-27 15:04:13 瀏覽:595
cod17編譯著色器卡住c盤滿了 發布:2024-11-27 14:55:56 瀏覽:386
鎖機軟體反編譯 發布:2024-11-27 14:36:02 瀏覽:148