111,119
社区成员
发帖
与我相关
我的任务
分享
--删除表
drop table A,B
--创建环境
create table A(ResearchCode int,ResearchContent varchar(1000))
insert into A select 1,'调查1'
union select 2,'调查2'
union select 3,'调查3'
union select 4,'调查4'
create table B(ResearchCode int,PeopleCode int, OutCome varchar(1000))
insert into B select 3,0001,'是'
--执行语句
declare @PeopleCode int
set @PeopleCode = 0001
select ResearchCode,ResearchContent,PeopleCode,OutCome from
(select A.ResearchCode,A.ResearchContent,isnull(PeopleCode,@PeopleCode) as PeopleCode,B.OutCome
from A left join B on A.ResearchCode = B.ResearchCode) as c
where c.PeopleCode = @PeopleCode
--(所影响的行数为 4 行)
ResearchCode ResearchContent PeopleCode OutCome
1 调查1 1 NULL
2 调查2 1 NULL
3 调查3 1 是
4 调查4 1 NULL
--执行语句
select B.ResearchCode,A.ResearchContent,B.PeopleCode,B.OutCome
from A inner join B on A.ResearchCode = B.ResearchCode
where B.PeopleCode = 0001
--创建环境
create table A(ResearchCode int,ResearchContent varchar(1000))
insert into A select 1,'调查1'
union select 2,'调查2'
union select 3,'调查3'
union select 4,'调查4'
create table B(ResearchCode int,PeopleCode int, OutCome varchar(1000))
insert into B select 1,0001,NULL
union select 2,0001,NULL
union select 3,0001,'是'
union select 4,0001,NULL
--执行语句
select B.ResearchCode,A.ResearchContent,B.PeopleCode,B.OutCome
from A inner join B on A.ResearchCode = B.ResearchCode
--(所影响的行数为 4 行)
ResearchCode ResearchContent PeopleCode OutCome
1 调查1 1 NULL
2 调查2 1 NULL
3 调查3 1 是
4 调查4 1 NULL