日期:2014-05-17 浏览次数:20608 次
create table t1
(
id int,
姓名 nvarchar(3)
)
insert into t1 values(1,'刘大')
insert into t1 values(2,'关二')
insert into t1 values(3,'张三')
insert into t1 values(4,'李四')
insert into t1 values(5,'王五')
create table t2
(
id int,
姓名 nvarchar(3)
)
insert into t2 values(1,'刘大')
insert into t2 values(2,'唐僧')
insert into t2 values(3,'孙悟空')
insert into t2 values(4,'李四')
insert into t2 values(5,'王五')
select t1.id,t1.姓名, case when t1.姓名 = t2.姓名 then 'y' else 'n' end from t1,t2
where t1.id = t2.id
/*
id,姓名,
1,刘大,y
2,关二,n
3,张三,n
4,李四,y
5,王五,y
(5 行受影响)
*/
select t2.id,t2.姓名, case when t1.姓名 = t2.姓名 then 'y' else 'n' end from t1,t2
where t1.id = t2.id
/*
id,姓名,
1,刘大,y
2,唐僧,n
3,孙悟空,n
4,李四,y
5,王五,y
(5 行受影响)