如何对此查询使用Oracle组函数计数和group by子句

时间:2015-08-12 16:55:00

标签: oracle

Create a query to display the total number of employees and, of that total, the number of
employees hired in 1995, 1996, 1997, and 1998. Create appropriate column headings.

enter image description here

假设员工表有以下字段

  1. emp_id number
  2. firstname varchar

  3. hire_date date 等

1 个答案:

答案 0 :(得分:1)

这可能会有所帮助!根据您的需要更换年份

   SELECT COUNT(*) "Total",
  SUM(DECODE(hire_date,'2010',1,0)) "2010 Count" ,
  SUM(DECODE(hire_date,'2015',1,0)) "2015 Count",
  SUM(DECODE(hire_date,'2014',1,0)) "2014 Count"
FROM emp;