日期:2014-05-18 浏览次数:20557 次
create table t1(id int,col varchar(10))
insert into t1 select 1,'agbf'
insert into t1 select 2,'fds'
insert into t1 select 3,'vaisud'
create table t2(id int,col int)
insert into t2 select 1,234
create table t3(id int,col int)
insert into t3 select 1,347145
insert into t3 select 1,102201
insert into t3 select 2,874
go
select a.id,sum(b.col)si,SUM(c.col)so
from t1 a left join t2 b on a.id=b.id
left join t3 c on a.id=c.id
group by a.id
select a.id,sum(b.col)si
from t1 a left join t2 b on a.id=b.id
group by a.id
select a.id,SUM(c.col)so
from t1 a left join t3 c on a.id=c.id
group by a.id
/*
id si so
----------- ----------- -----------
1 468 449346
2 NULL 874
3 NULL NULL
警告: 聚合或其他 SET 操作消除了 Null 值。
(3 行受影响)
id si
----------- -----------
1 234
2 NULL
3 NULL
警告: 聚合或其他 SET 操作消除了 Null 值。
(3 行受影响)
id so
----------- -----------
1 449346
2 874
3 NULL
警告: 聚合或其他 SET 操作消除了 Null 值。
(3 行受影响)
*/
go
drop table t1,t2,t3