日期:2014-05-17  浏览次数:20732 次

SQL语句的问题,求助!!!

select t.ID,
       t.SCHOOL_NAME,
       (select count(*) from T_STUDENT where SCHOOL_ID = t.ID and ISACTIVE = 1) STUCOUNT,
       (select count(*) from (select distinct STUDENT_ID from T_BUSINESS where SCHOOL_ID = t.ID and (STATUS = 1 or STATUS = 2))) BIZCOUNT
 from (select tb.*, rownum rn from T_SCHOOL tb where ISACTIVE = 1 and rownum <= 20) t
 where rn > 0 order by CITY, REGIONNAME, SCHOOL_NAME;


获取BIZCOUNT的时候里面的t.ID得不到值,有什么办法吗?
------解决方案--------------------
select t.ID,
       t.SCHOOL_NAME,
       (select count(*) from T_STUDENT where SCHOOL_ID = t.ID and ISACTIVE = 1) STUCOUNT,
       (select count(distinct STUDENT_ID) from T_BUSINESS where SCHOOL_ID = t.ID and (STATUS = 1 or STATUS = 2)) BIZCOUNT
 from (select tb.*, rownum rn from T_SCHOOL tb where ISACTIVE = 1 and rownum <= 20) t
 where rn > 0 order by CITY, REGIONNAME, SCHOOL_NAME;