当前位置:首页 » 编程语言 » 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;

热点内容
存储器国产率 发布:2025-01-19 07:04:36 浏览:566
锐程cc蓝鲸版选什么配置 发布:2025-01-19 06:56:28 浏览:168
城镇居民医保卡的原始密码是多少 发布:2025-01-19 06:55:54 浏览:787
wifi密码如何修改密码 发布:2025-01-19 06:39:06 浏览:961
sqlserver认证 发布:2025-01-19 06:34:30 浏览:815
小米8se安卓p有什么功能 发布:2025-01-19 06:25:22 浏览:358
ucos和linux 发布:2025-01-19 06:24:06 浏览:470
关闭chrome缓存 发布:2025-01-19 05:43:55 浏览:830
修改svn服务器ip地址 发布:2025-01-19 05:32:00 浏览:441
iis服务器搭建出现404错误 发布:2025-01-19 05:26:39 浏览:312