急求一sql语句,解决后立马给分!!!!

卷泥巴重来 2013-03-20 11:39:42
链表查询,

表A
字段:
webid code regnum
232 1143 23
242 1143 4
200 1143 21
212 1143 7
221 1143 17
111 1143 12
101 1143 6
231 1143 7
265 1143 9

表B
字段:
webid code hynum
232 1143 2
242 1143 8
200 1143 21
212 1143 7


要查询结果为:

webid code regnum hynum
232 1143 23 2
242 1143 4 8
200 1143 21 21
212 1143 7 7
221 1143 17 0
111 1143 12 0
101 1143 6 0
231 1143 7 0
265 1143 9 0


求sql语句


...全文
267 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
苦苦的潜行者 2013-03-22
  • 打赏
  • 举报
回复
引用 9 楼 xiaolinyouni 的回复:
SQL code?1select a.*,isnull(b.hynum,0) from a join b on a.webid=b.webid and a.code=b.code
select a.*,isnull(b.hynum,0) from a left join b on a.webid=b.webid and a.code=b.code
苦苦的潜行者 2013-03-22
  • 打赏
  • 举报
回复
select a.*,isnull(b.hynum,0) from a join b on a.webid=b.webid and a.code=b.code
-Tracy-McGrady- 2013-03-22
  • 打赏
  • 举报
回复
select A.webid,A.code,A.regnum,isnull(B.hynum,0) as hynum from A left join B on A.webid = B.webid 左链接就可以了
kk_lucky 2013-03-22
  • 打赏
  • 举报
回复
赞成5楼的意见
棉花棒棒糖 2013-03-22
  • 打赏
  • 举报
回复

select A.webid,A.code,A.regnum,hynum=isnull(B.hynum,0) from A  left join B on A.webid = B.webid
pard521 2013-03-21
  • 打赏
  • 举报
回复
select A.webid,A.code,A.regnum,hynum=isnull(B.hynum,0) from A  left join B on A.webid = B.webid
  • 打赏
  • 举报
回复
select a.*, b.hynum from a left join b on a.webid=b.webid and a.code=b.code
szm341 2013-03-20
  • 打赏
  • 举报
回复
select a.*,isnull(b.hynum,0)hynum from a left join b on a.webid=b.webid and a.code=b.code
搬砖的码农 2013-03-20
  • 打赏
  • 举报
回复
select a.*,b.hynum 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

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧