日期:2014-05-17  浏览次数:20652 次

急求一sql语句,解决后立马给分!!!!
链表查询,

    表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语句



------解决方案--------------------
select a.*,b.hynum from a left join b on a.webid=b.webid
------解决方案--------------------
select a.*,isnull(b.hynum,0)hynum
from a left join b on a.webid=b.webid and a.code=b.code
------解决方案--------------------
select a.*, b.hynum
from a left join b on a.webid=b.webid and a.code=b.code
------解决方案--------------------
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