select 交换机Id.小区名称,count(*)
from 交换机信息表 ,配线信息表 ,小区信息表
where 小区信息表.小区id=配线信息表.小区id
and 配线信息表.配线id=交换机信息表.配线id
group by 交换机Id.小区名称
from 交换机信息表 ,配线信息表 ,小区信息表
where 小区信息表.小区id=配线信息表.小区id
and 配线信息表.配线id=交换机信息表.配线id
group by 交换机Id.小区名称
DECLARE
i number(2);
tempi number(6);
CURSOR xiaoquid IS select distinct(小区ID) from l_小区信息表;
begin
select count(distinct(小区ID)) into i from l_小区信息表;
open xiaoquid;
<<label_>>
fetch xiaoquid into tempi;
select count(交换机ID) from l_交换机信息表 t where t.配线间id in(select 配线间id from l_配线间信息表 where 小区id=tempi);//报告该行缺少into语句
i:=i-1;
if i>0 then goto label_;
end if;
close xiaoquid;
end;
select
count(*) 交换机台数
from
table1 a,
table2 b,
table3 c
where
1=1
and a.小区名称='小区1'
and a.小区id=b.小区id
and b.配线id=c.配线id
建议发问题时能给出点样例数据,我上面写的不知道是不是你的需求可以实现的.