我将这些表格包含以下列:
Employee24 (EMPLOYEEID, FIRSTNAME, LASTNAME, GENDER);
PROJECT24 (PROJECTID PROJECTNAME EMPLOYEEID);
我想编写一个查询来查找最多雇员人数的项目。
SELECT FIRSTNAME, LASTNAME
FROM EMPLOYEE24 E
WHERE E.EMPLOYEEID IN ( SELECT L2.EMPLOYEEID
FROM PROJECT24 L2 group by l2.employeeid)\\
答案 0 :(得分:0)
您可以尝试这样的事情(虽然我很确定它可以通过其他方式完成):
SELECT *
FROM (SELECT prj.projectid,
prj.projectname,
COUNT(*) AS number_employees
FROM project24 prj
JOIN employee24 emp
ON prj.employeeid = emp.employeeid
GROUP BY prj.projectid,
prj.projectname
ORDER BY number_employees DESC)
WHERE ROWNUM = 1;
答案 1 :(得分:0)
如果有关系,你想做什么?这是一个重要问题,为什么row_number()
/ rank()
可能是更好的选择:
select p.*
from (select p.projectid, p.projectname, count(*) as num_employees,
rank() over (order by count(*) desc) as seqnum
from project25 p
group by p.projectid, p.projectname
) p
where seqnum = 1;
注意:
row_number()
。employee24
。project_employees
。那应该有projectid
,但不是名字。该名称应位于project24
。