select * from (
  select *, (select count(*) from table) from table
) as temp执行以上语句,报错:invalid use of an aggegate function!
有人可以解释一下吗?注:请不要使用 select *, count(*) from table group by 列。

解决方案 »

  1.   

    select *, (select count(*) from table) from table这个不就可以了嘛。为什么还要再套一层
      

  2.   

    select * from (
      select code as 'a', [name] as 'b', (select count(*) from table) as 'c' from table
    ) as temptable 表有两个字段,code和name。执行以上语句,报错:invalid use of an aggegate function!
    有人可以解释一下吗?
      

  3.   

    select code as 'a', [name] as 'b', (select count(*) from table) as 'c' from table
    这个也报错,吗?
      

  4.   

    select code as a, [name] as b, (select count(*) from table) as c from table
      

  5.   

    select * from (
      select code as 'a', [name] as 'b', (select count(*) from table) as 'c' from table
    ) as temptable 表有两个字段,code和name。执行以上语句,报错:invalid use of an aggegate function!
    有人可以解释一下吗?
      

  6.   

    ------try it ...good luck
    select * from 
    (
       select t.*,select count(*)over(order by 1) cn from table t
    ) temp
      

  7.   


    --还没解决?select * from (
      select a.*, (select count(*) from table) from table a
    )  temp
      

  8.   

    SQL> 
    SQL> select * from (
      2    select a.*, (select count(*) from emp) from emp a
      3  )   temp
      4  /
     
    EMPNO ENAME      JOB         MGR HIREDATE          SAL      COMM DEPTNO (SELECTCOUNT(*)FROMEMP)
    ----- ---------- --------- ----- ----------- --------- --------- ------ -----------------------
     7369 SMITH      CLERK      7902 1980-12-17     800.00               20                      14
     7499 ALLEN      SALESMAN   7698 1981-2-20     1600.00    300.00     30                      14
     7521 WARD       SALESMAN   7698 1981-2-22     1250.00    500.00     30                      14
     7566 JONES      MANAGER    7839 1981-4-2      2975.00               20                      14
     7654 MARTIN     SALESMAN   7698 1981-9-28     1250.00   1400.00     30                      14
     7698 BLAKE      MANAGER    7839 1981-5-1      2850.00               30                      14
     7782 CLARK      MANAGER    7839 1981-6-9      2450.00               10                      14
     7788 SCOTT      ANALYST    7566 1987-4-19     3000.00               20                      14
     7839 KING       PRESIDENT       1981-11-17    5000.00               10                      14
     7844 TURNER     SALESMAN   7698 1981-9-8      1500.00      0.00     30                      14
     7876 ADAMS      CLERK      7788 1987-5-23     1100.00               20                      14
     7900 JAMES      CLERK      7698 1981-12-3      950.00               30                      14
     7902 FORD       ANALYST    7566 1981-12-3     3000.00               20                      14
     7934 MILLER     CLERK      7782 1982-1-23     1300.00               10                      14
     
    14 rows selected
     
      

  9.   

    楼上用的是什么数据库。为什么 Sybase IQ 不行呢?