1

我在 MySQL 中有这张表(名为 EMP):

EMPNO ENAME   JOB       MGR  HIREDATE     SAL      COMM DEPTNO
----- -----  -------   ----  -------- --------  ------- ------
7369 SMITH  CLERK     7902 13-JUN-83   800.00              20
7499 ALLEN  SALESMAN  7698 15-AUG-83 1,600.00   300.00     30
7521 WARD   SALESMAN  7698 26-MAR-84 1,250.00   500.00     30
7566 JONES  MANAGER   7839 31-OCT-83 2,975.00              20
7654 MARTIN SALESMAN  7698 05-DEC-83 1,250.00 1,400.00     30
7698 BLAKE  MANAGER   7839 11-JUL-84 2,850.00              30
7782 CLARK  MANAGER   7839 14-MAY-84 2,450.00              10
7788 SCOTT  ANALYST   7566 05-MAR-84 3,000.00              20
7839 KING   PRESIDENT      09-JUL-84 5,000.00              10
7844 TURNER SALESMAN  7698 04-JUN-84 1,500.00  .00         30
7876 ADAMS  CLERK     7788 04-JUN-84 1,100.00              20
7900 JAMES  CLERK     7698 23-JUL-84   950.00              30
7902 FORD   ANALYST   7566 05-DEC-83 3,000.00              20
7934 MILLER CLERK     7782 21-NOV-83 1,300.00              10

当注册的员工(行)数量最多时,如何编写返回年份(HIREDATE 列)的 Select 查询?

4

4 回答 4

1

关于什么

SELECT YEAR(hiredate) FROM emp 
  GROUP BY YEAR(hiredate) 
  ORDER BY COUNT(*) DESC
  LIMIT 1

?

于 2012-10-16T17:37:54.043 回答
0

关于什么:

SELECT COUNT(1), YEAR(HIREDATE) FROM EMP GROUP BY YEAR(HIREDATE);
于 2012-10-16T17:34:52.440 回答
0

尝试这个:

select year(hiredate), count(*) from emp 
group by year(hiredate) order by 2 desc limit 1
于 2012-10-16T17:35:05.723 回答
0

尝试

SELECT count(*) as total FROM emp GROUP BY hiredate ORDER BY total DESC LIMIT 1;
于 2012-10-16T17:35:06.200 回答