SQL:查找在一周中特定日期雇用的所有员工

时间:2015-01-22 18:47:55

标签: sql oracle count max

我很难找到所有雇员,这些雇员是在雇用率最高的一周(星期一,星期二等)工作的。

例如:如果星期一是招聘人数最多的那一天,我想显示一周中当天雇用的所有员工。

我发现哪些日子的招聘人数最多:

SELECT COUNT(*), TO_CHAR(HIRE_DATE,'DAY') DAY
FROM EMPLOYEES
GROUP BY TO_CHAR(HIRE_DATE,'DAY')
HAVING COUNT (*)=(SELECT MAX(COUNT(*))FROM EMPLOYEES GROUP BY TO_CHAR(HIRE_DATE,'DAY'));

但我无法显示当天雇用的所有员工。提前感谢您的时间。

2 个答案:

答案 0 :(得分:1)

我不了解Oracle语法,但在该查询上加入EMPLOYEES。类似于:

SELECT  e.*
FROM EMPLOYEES e
INNER JOIN
    (SELECT <employee id>, TO_CHAR(HIRE_DATE,'DAY') DAY
    FROM EMPLOYEES
    GROUP BY TO_CHAR(HIRE_DATE,'DAY')
    HAVING COUNT (*)=(SELECT MAX(COUNT(*))FROM EMPLOYEES GROUP BY TO_CHAR(HIRE_DATE,'DAY'))) AS empdays
    ON TO_CHAR(e.HIRE_DATE, 'DAY') = empdays.DAY;

答案 1 :(得分:0)

怎么样:

select * from employees
where to_char(HIRE_DATE,'DAY') in

SELECT TO_CHAR(HIRE_DATE,'DAY') DAY
FROM EMPLOYEES
GROUP BY TO_CHAR(HIRE_DATE,'DAY')
HAVING COUNT (*)=(SELECT MAX(COUNT(*))FROM EMPLOYEES GROUP BY TO_CHAR(HIRE_DATE,'DAY'));