当我在sql中编写此查询时显示错误(ORA-00998:必须使用列别名命名此表达式)
create or replace view vw_salary as select dname ,
(select count(*) from employee where dno=department.dnumber) from department;
答案 0 :(得分:1)
视图中的列需要具有名称。因此,在子查询后需要as
:
create or replace view vw_salary as
select dname,
(select count(*) from employee e where e.dno = d.dnumber
) as NumEmployees
from department d;
我强烈建议您使用表别名和限定列名(即使用表别名)。对于相关子查询来说,特别很重要,因为它很容易出错并且难以调试。
我还注意到该视图名为vw_salary
,但没有工资信息。
答案 1 :(得分:1)
select department.dname, count(employee.dno) as empCount
from department
left join employee
on employee.dno = department.dnumber
group by department.dname
我认为这比你当前的格式更有效
答案 2 :(得分:0)
这意味着您需要为计数表达式命名...尝试以下操作,您可以更改" TheCount"您要使用的任何名称。
create or replace view vw_salary as select dname ,
(select count(*) AS TheCount from employee where dno=department.dnumber) from department;