日期:2014-05-18  浏览次数:20498 次

求助各位大侠:按照A表的某一键值统计在C表出现的总数
有A,B,C三张表中,A.sn=B.index, B.ip=C.ip
按照A表的sn,分别统计在C表中的总数。

------解决方案--------------------
SQL code
select
  a.sn,count(c.ip)
from
  a,b,c
where
  A.sn=B.index and B.ip=C.ip
group by
  a.sn

------解决方案--------------------
SQL code
select a.sn,c.cnt
from a
join b on A.sn=B.[index]
join (select ip,count(1) as cnt from c group by ip) c on b.ip=c.ip
group by a.sn,c.cnt

------解决方案--------------------
SQL code

select
  a.sn,count(c.ip)
from
  a,b,c
where
  A.sn=B.index and B.ip=C.ip
group by
  a.sn

------解决方案--------------------
SQL code
select
  a.sn,count(c.ip)
from a
inner join b on A.sn=B.index 
inner join c on B.ip=C.ip
group by a.sn