oracle pl/sql格式:
select x.f1, x.f2, sum(f3)
from table1 x, table2 y
where x.f1=y.f1 (+)
and x.f2=y.f2 (+)
group by x.f1,x.f2;sql server t/sql或access格式:
select x.f1, x.f2, sum(f3)
from table1 x left join table2 y
on (x.f1=y.f1 and x.f2=y.f2)
group by x.f1,x.f2;其它格式不知道
select x.f1, x.f2, sum(f3)
from table1 x, table2 y
where x.f1=y.f1 (+)
and x.f2=y.f2 (+)
group by x.f1,x.f2;sql server t/sql或access格式:
select x.f1, x.f2, sum(f3)
from table1 x left join table2 y
on (x.f1=y.f1 and x.f2=y.f2)
group by x.f1,x.f2;其它格式不知道
select x.f1, x.f2, sum(f3)
from table1 as x left join table2 as y
on (x.f1=y.f1 and x.f2=y.f2)
group by x.f1,x.f2;
from table1 x left join (select F1,F2,sum(f3) as F3 from table2 group by F1,F2) as y
on (x.f1=y.f1 and x.f2=y.f2)
(select distinct f2 from a)as t1 left join
(select f2,sum(f3) from b group by f2)as t2
on t1.f2=t2.f2;弱水您好,怎么现在也跑到这边来了!
group by a.f1(,a.f2)
union
select f2,0 from a where not exists ( select * from b where a.f2=b.f2)
order by f2
你的方法可行,但是查询效率不太好,我测了一下:
select f2,sum(f3) from b group by f2
union
select f2,0 from a where not exists ( select * from b where a.f2=b.f2)
order by f2比单一的:select f2,sum(f3) from b group by f2
速度上差2倍多。还有没有更好的方法?
查一下help