从视图中获取最大计数

时间:2015-04-28 22:59:20

标签: sql oracle view count max

我创建了一个视图,允许我查看医生的约会数量。

查看代码:

create view DocApps as
select d.doctorid, d.surname ||','|| d.given as "Doctor", count(*) as "Appointments"
from doctor d, appointment
where d.doctorid=appointment.doctorid
group by d.doctorid, d.surname, d.given;

我现在需要向医生展示最多的约会,我已经使用过这段代码,因为它在以前的查询中有效:

select Doctor, Appointments
from docapps
where Appointments in (select max(Appointments)
from docapps);

但它正在回复"约会" :无效的标识符,当我指定它是那个?

1 个答案:

答案 0 :(得分:1)

使用双引号(")会使表格和列等对象名称区分大小写,这就是导致问题的原因。只需从视图声明中删除它们就可以了:

CREATE VIEW DocApps AS
SELECT   d.doctorid, d.surname ||','|| d.given AS Doctor, 
         COUNT(*) AS Appointments
FROM     doctor d, appointment
WHERE    d.doctorid=appointment.doctorid
GROUP BY d.doctorid, d.surname, d.given;