0

好的,所以我在 Oracle 中有两个表:

CAR,具有属性所有者(参考 EMPLOYEE(ssn))

EMPLOYEE,具有属性名称,ssn。

我需要获得汽车数量最多的员工的姓名和 ssn,但我无法理解如何以这种方式使用聚合函数......

我尝试过类似以下的方法:

    SELECT name, ssn
    FROM EMPLOYEE
    WHERE ssn IN (SELECT owner
                  FROM CAR
                  HAVING COUNT(owner) = MAX(COUNT(owner))
                  GROUP BY owner)

但它似乎没有返回任何东西......我什至在正确的轨道上吗?

4

2 回答 2

1
select * from EMPLOYEE
where ssn = (
  select min(owner) keep (dense_rank first order by count(1) desc, owner) 
  from CAR 
  group by owner
)

小提琴

于 2013-10-14T19:20:11.997 回答
1
select e.name,e.ssn,count(*)
from EMPLOYEE e 
inner join CAR c on e.ssn = c.owner
group by e.name,e.ssn
于 2013-10-14T19:17:19.310 回答