ORA-00913: 当我在 SQL*Plus 中运行查询时出现太多值错误

发布于 2024-12-03 19:29:32 字数 1719 浏览 0 评论 0原文

我正在尝试获取 dname、loc,并计算 ename,另外我想包含表中的 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>

I am trying to get the dname, loc, and count the ename's, plus I want to include the sal from the table. Can someone tell me what I am doing wrong.

Heres my statement with the error I get

 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>

Heres my table

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>

Heres the second table

SQL> select * from dept;

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

 SQL>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅此而已 2024-12-10 19:29:32

要获取人数和工资总额,请尝试此...

 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

To get number of people and total Salary, try this...

 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

You can get other things as well

 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
暮年 2024-12-10 19:29:32

标量(内联)游标在其投影中只能有一个值。

如果您想要多个值,请使用联接并聚合所有值,正如 Sparky 所建议的

The scalar (inline) cursor can only have only one value in its projection.

If you want to have more than one value, use a join and aggregate all the values, as Sparky suggests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文