select 交换机Id.小区名称,count(*)
from 交换机信息表 ,配线信息表 ,小区信息表
where 小区信息表.小区id=配线信息表.小区id
and 配线信息表.配线id=交换机信息表.配线id
group by 交换机Id.小区名称

解决方案 »

  1.   

    我使用游标编写函数如下,报告说最长的select也就是查询结果那行无法返回结果,诡异。
    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;
      

  2.   


    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
            
    建议发问题时能给出点样例数据,我上面写的不知道是不是你的需求可以实现的.
      

  3.   

    select count(distinct(交换机Id)) from 交换机信息表 where 配线id in(select 配线id from 配线信息表 where 小区id=(select distinct(小区Id)from 小区信息表))将=改为inselect count(交换机ID) from l_交换机信息表 t where t.配线间id in(select 配线间id from l_配线间信息表 where 小区id=tempi);//报告该行缺少into语句count(交换机ID) 加上 into switchnum ,然后将switchnum作为函数的返回值。