

通过查询,形成以下结果:
id name type 今日发送 今日回收 今日结余 昨日累计结余
10001 天津佰润-天津 null 0 0 0 -1
10001 天津佰润-天津 1000 1 0 -1 -1
10001 天津佰润-天津 800 0 0 0 1
------解决方案--------------------
select tb1.*,tb2.[昨日累计结余] from tb1,tb2 where tb1.id=tb2.id
------解决方案--------------------
select a.id,a.name,a.type,b.今日发送,b.今日回收,b.今日结余,a.昨日累计结余
from table2 a left join table1 b on a.id=b.id
------解决方案--------------------
create table hzk(id varchar(20),name nvarchar(30),type int,jrfs int,jrhs int,jrjy int)
insert into hzk
select '100001',N'天津佰润-天津',1000,1,0,-1
create table mxk(id varchar(20),name nvarchar(30),type int,zrljjy int)
insert into mxk
select '100001',N'天津佰润-天津',null,-1
union
select '100001',N'天津佰润-天津',1000,-1
union
select '100001',N'天津佰润-天津',800,1
select a.id,a.name,a.type,今日发送=isnull(b.jrfs,0),今日回收=isnull(b.jrhs,0) ,
isnull(jrjy,0) as 今日结余,a.zrljjy 昨日累计结余 from mxk a left join hzk b
on a.type=b.type
------解决方案--------------------
被忽悠了吧。我看有多少人按id连接
------解决方案--------------------
select a.id,a.name,a.type,今日发送=isnull(b.jrfs,0),今日回收=isnull(b.jrhs,0) ,
isnull(jrjy,0) as 今日结余,a.zrljjy 昨日累计结余 from mxk a left join hzk b
on a.type=b.type and a.id=b.id
我觉得3楼还要加上一个条件,应为可能id不同但是有相同的type