显示在雇用最多雇员人数的当天雇用的所有员工

时间:2017-02-07 02:44:06

标签: mysql sql-server

SELECT last_name, TO_CHAR(hire_date, ’DAY’) day

FROM employees

WHERE TO_CHAR(hire_date, ’Day’) =

(SELECT TO_CHAR(hire_date, ’Day’)

FROM employees

GROUP BY TO_CHAR(hire_date, ’Day’)

HAVING COUNT(*) = (SELECT MAX(COUNT(*))

FROM employees

GROUP BY TO_CHAR(hire_date, ’Day’)));

错误显示

  

Msg 102,Level 15,State 1,Line 1   '''附近的语法不正确。   Msg 102,Level 15,State 1,Line 7   '''附近的语法不正确。   Msg 102,Level 15,State 1,Line 17   '''附近的语法不正确。

我们正在使用MS SQL Server Management Studio

3 个答案:

答案 0 :(得分:1)

SELECT last_name,TO_CHAR(hire_date,'DAY') as day 
FROM employees
WHERE TO_CHAR(hire_date,'DAY') IN (SELECT TO_CHAR(hire_date,'DAY')
                                   FROM employees GROUP BY TO_CHAR(hire_date,'DAY')
                                   HAVING COUNT(*) = (SELECT MAX(COUNT(*)) 
                                                      FROM employees
                                                      GROUP BY 
                                                      TO_CHAR(hire_date,'DAY')));

答案 1 :(得分:0)

SELECT last_name, TO_CHAR(hire_date, ’DAY’) day    
FROM employees
WHERE hire_date =
(SELECT hire_date
FROM employees
GROUP BY hire_date
HAVING COUNT(*) = MAX(COUNT(*)))
你能试试吗?

答案 2 :(得分:0)

SELECT last_name,TO_CHAR(hire_date,'DAY') as Week_Day
FROM employees
WHERE TO_CHAR(hire_date,'DAY') 
IN (SELECT T.day
    FROM (SELECT TO_CHAR(hire_date,'DAY') as day,COUNT(TO_CHAR(hire_date,'DAY')) as cnt
          FROM employees GROUP BY TO_CHAR(hire_date,'DAY'))T
          WHERE T.cnt = (SELECT MAX(T.cnt) 
                         FROM (SELECT TO_CHAR(hire_date,'DAY') as 
                                      day,COUNT(TO_CHAR(hire_date,'DAY')) as cnt
                               FROM employees GROUP BY TO_CHAR(hire_date,'DAY'))T))