--不知道是不是想要这样的: select a.hpzl,a.hphm,count(*)次数 from tabA a,tabB b where a.hpzl=b.hpzl and a.hphm=b.hphm and exists(select 1 from tabC c where a.hpzl=c.hpzl and a.hphm=c.hphm)
--替paddy写完 select a.hpzl,a.hphm,count(*)次数 from tabA a,tabB b where a.hpzl=b.hpzl and a.hphm=b.hphm and exists(select 1 from tabC c where a.hpzl=c.hpzl and a.hphm=c.hphm) group by a.hpzl,a.hphm
--难道是这样?楼主还是最好给点数据和结果,好理解些 select a.hpzl,a.hphm,count(*)次数 from tabA a,tabB b,tabC c where (a.hpzl=b.hpzl and a.hphm=b.hphm) or (a.hpzl=c.hpzl and a.hphm=c.hphm) group by a.hpzl,a.hphm
select a.hpzl,a.hphm,sum(case when (a.hpzl = b.hpzl and a.hphm = b.hphm) or (a.hpzl = c.hpzl and a.hphm = c.hphm) then 1 else 0 end)[次数] from a,b,c where a.id = b.id and a.id = c.id
select a.hpzl,a.hphm,isnull(a.num,o) + isnull(b.num,0) + isnull(c.num,0) as num from a inner join b on a.hpzl = b.hpzl and a.hphm = b.hphm inner join c on a.hpzl = c.hpzl and a.hphm = c.hphm--或者把inner join 换成 left join
-- 打错了,是 isnull(a.num,0)
你不在sql server版呆着,怎么跑这里了呢? isnull是sql server 的语法吧,oracle是nvl(a.num,0)
--试试 没看清你的意图select hpzl,hphm,count(*) from (select hpzl,hphm from taba union all select hpzl,hphm from tabb union all select hpzl,hphm from tabc) group by hpzl,hphm
结果就是3列,hpzl,hphm,次数,这3列。
--不知道是不是想要这样的:
select a.hpzl,a.hphm,count(*)次数
from tabA a,tabB b
where a.hpzl=b.hpzl and a.hphm=b.hphm
and exists(select 1 from tabC c where a.hpzl=c.hpzl and a.hphm=c.hphm)
select a.hpzl,a.hphm,count(*)次数
from tabA a,tabB b
where a.hpzl=b.hpzl and a.hphm=b.hphm
and exists(select 1 from tabC c where a.hpzl=c.hpzl and a.hphm=c.hphm)
group by a.hpzl,a.hphm
--难道是这样?楼主还是最好给点数据和结果,好理解些
select a.hpzl,a.hphm,count(*)次数
from tabA a,tabB b,tabC c
where (a.hpzl=b.hpzl and a.hphm=b.hphm)
or (a.hpzl=c.hpzl and a.hphm=c.hphm)
group by a.hpzl,a.hphm
from a,b,c
where a.id = b.id and a.id = c.id
select a.hpzl,a.hphm,isnull(a.num,o) + isnull(b.num,0) + isnull(c.num,0) as num
from a inner join b on a.hpzl = b.hpzl and a.hphm = b.hphm
inner join c on a.hpzl = c.hpzl and a.hphm = c.hphm--或者把inner join 换成 left join
-- 打错了,是 isnull(a.num,0)
isnull是sql server 的语法吧,oracle是nvl(a.num,0)
--试试 没看清你的意图select hpzl,hphm,count(*)
from (select hpzl,hphm from taba
union all
select hpzl,hphm from tabb
union all
select hpzl,hphm from tabc)
group by hpzl,hphm