select a.*,(select count(*) from deeptree where parentid = id) as children from deeptree a where id=parentid

解决方案 »

  1.   

    还不行。
    新表中有一个原表的LINK字段未显示,而且也没有别名字段CHILDREN
      

  2.   

    用SQL*PLUS执行的结果如下:SQL> select *,(select count(*) from deeptree where parentid=id) as children
      2  from deeptree
      3  whrere id=parentid;
    select *,(select count(*) from deeptree where parentid=id) as children
            *
    ERROR 位于第 1 行:
    ORA-00923: 未找到预期 FROM 关键字错在何处?
      

  3.   

    select a.*,  (select count(*) from deeptree where parentid = id) as children 
    from deeptree a 
    where a.id=a.parentid这样语法肯定是没错的,不过逻辑就有点问题了,count(*)求出来,却不分组,意义何在?
      

  4.   

    --查询
    select * from scott.emp;
    --建表
    create table temp_1 as select a.*, a.empno as empno2 from scott.emp a ;
    --在查询
    select a.*,  (select count(*) from temp_1 where empno = empno2) as children 
    from temp_1 a 
    where a.empno=a.empno2