[oracle]ORA-00913: 太多值错误在 SQL 中运行查询时 * 加上

标签: ora-00913 sql Oracle
发布时间: 2014/3/8 11:02:26
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我想拿条,loc,和计数易名,再加上我想要包括从表 sal。谁能告诉我我做错了。

下面是我的发言,我得到的错误

 SQL> select dname, loc, (select count(ename), sal from emp where DEPTNO =   dept.deptno) as Number_of_people  from dept;
 select dname, loc, (select count(ename), sal from emp where DEPTNO = dept.deptno) as  Number_of_people  from dept
                *
 ERROR at line 1:
 ORA-00913: too many values


 SQL>

下面是我的表

SQL> select empno, ename, job, hiredate, sal from emp;

 EMPNO ENAME      JOB       HIREDATE         SAL
---------- ---------- --------- --------- ----------
  7839 KING       PRESIDENT 17-NOV-81       5000
  7698 BLAKE      MANAGER   01-MAY-81       2850
  7782 CLARK      MANAGER   09-JUN-81       2450
  7566 JONES      MANAGER   02-APR-81       2975
  7654 MARTIN     SALESMAN  28-SEP-81       1250
  7499 ALLEN      SALESMAN  20-FEB-81       1600
  7844 TURNER     SALESMAN  08-SEP-81       1500
  7900 JAMES      CLERK     03-DEC-81        950
  7521 WARD       SALESMAN  22-FEB-81       1250
  7902 FORD       ANALYST   03-DEC-81       3000
  7369 SMITH      CLERK     17-DEC-80        800

 EMPNO ENAME      JOB       HIREDATE         SAL
 ---------- ---------- --------- --------- ----------
  7788 SCOTT      ANALYST   09-DEC-82       3000
  7876 ADAMS      CLERK     12-JAN-83       1100
  7934 MILLER     CLERK     23-JAN-82       1300

 14 rows selected.

 SQL>

下面是第二个表

SQL> select * from dept;

DEPTNO DNAME          LOC
---------- -------------- -------------
    10 ACCOUNTING     NEW YORK
    20 RESEARCH       DALLAS
    30 SALES          CHICAGO
    40 OPERATIONS     BOSTON

 SQL>

解决方法 1:

获取数字的人,工资总额,试试这个......

 select dept.dname, dept.loc, 
        count(emp.ename) as Number_of_people, sum(emp.sal) as Total_Salary
 from emp 
 join dept on emp.DEPTNO = dept.deptno
 group by dept.dname,dept.loc

你可以得到其他的东西,以及

 select dept.dname, dept.loc, 
        count(emp.ename) as Number_of_people, 
        sum(emp.sal) as Total_Salary,
        avg(emp.sal) as Average_salary,
        min(emp.hiredate) as First_dept_hire,
        max(emp.hireDate) as Last_dept_hire
 from emp 
 join dept on emp.DEPTNO = dept.deptno
 group by dept.dname,dept.loc
官方微信
官方QQ群
31647020