62,052
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据:[Dt1]
if object_id('[Dt1]') is not null drop table [Dt1]
create table [Dt1]([A] varchar(4))
insert [Dt1]
select 'E_01' union all
select 'E_02' union all
select 'F_02' union all
select 'H_06'
--> 测试数据:[Dt2]
if object_id('[Dt2]') is not null drop table [Dt2]
create table [Dt2]([A] varchar(4))
insert [Dt2]
select 'E_01' union all
select 'E_03' union all
select 'E_02' union all
select 'F_01' union all
select 'F_02' union all
select 'H_06'
select * from [Dt2]
order by case when exists (select 1 from [Dt1] where [Dt2].A=A) then 0
else 1 end
/*
A
----
E_01
E_02
F_02
H_06
F_01
E_03
(6 行受影响)
*/
drop table [Dt1]
drop table [Dt2]