27,579
社区成员
发帖
与我相关
我的任务
分享
select a.*,isnull(b.hynum,0) from a left join b on a.webid=b.webid and a.code=b.code
select a.*,isnull(b.hynum,0) from a join b on a.webid=b.webid and a.code=b.code
select A.webid,A.code,A.regnum,hynum=isnull(B.hynum,0) from A left join B on A.webid = B.webid
select A.webid,A.code,A.regnum,hynum=isnull(B.hynum,0) from A left join B on A.webid = B.webid
if object_id('A') is not null
drop table A
create table A
(
webid int primary key ,
code int ,
regnum int
)
if object_id('B') is not null
drop table B
create table B
(
webid int primary key ,
code int ,
hynum int
)
insert A
select 232,1143,23 union all
select 242,1143,4 union all
select 200,1143,21 union all
select 212,1143,7 union all
select 221,1143,17 union all
select 111,1143,12 union all
select 101,1143,6 union all
select 231,1143,7 union all
select 265,1143,9
insert B
select 232,1143,2 union all
select 242,1143,8 union all
select 200,1143,21 union all
select 212,1143,7
--左连接
select A.webid,A.code,A.regnum,hynum=isnull(B.hynum,0) from A left join B on A.webid = B.webid