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

Questions by adarsh_sp   answers by adarsh_sp

Showing Answers 1 - 25 of 25 Answers

select Count(*) as NumberOfEmployees,

EmployeesHiredIn1995_1996_1997_1998 =

(select count(*) from employees

where hiredate like '%1995%'

or hiredate like '%1996%'

or hiredate like '%1997%'

or hiredate like '%1998%')

from employees

  Was this answer useful?  Yes

Sneha Atre

  • Oct 11th, 2006
 

select count(*)

from employees

where hiredate in(1995,1996,1997,1998);

Manjunath

  • Oct 19th, 2006
 

Check this......

select count(*) Count, to_char(hiredate, 'YYYY') YEAR from emp group by rollup( to_char(hiredate, 'YYYY'))

  Was this answer useful?  Yes

Sachin

  • Oct 19th, 2006
 

Select

count(emp_code),

count(case when TO_NUMBER(to_CHAR(hire_date,'YYYY'))=1995 then (emp_code) end) as hire_1995

count(case when TO_NUMBER(to_CHAR(hire_date,'YYYY'))=1996 then (emp_code) end) as hire_1996

from employees

--similary the query will continue. remember that the fields are from one table and you are not doing any dimension querying. only the fact info is being queried

  Was this answer useful?  Yes

select

count(decode(to_char(hiredate, 'yyyy') , '1995', hiredate, null)) hired_in_1995,
count(decode(to_char(hiredate, 'yyyy') , '1996', hiredate, null)) hired_in_1996,

count(decode(to_char(hiredate, 'yyyy') , '1997', hiredate, null)) hired_in_1997,

count(decode(to_char(hiredate, 'yyyy') , '1998', hiredate, null)) hired_in_1998,
count(*) total_emp
from emp;

  Was this answer useful?  Yes

Anil Patra

  • Dec 10th, 2006
 

Check this out.

select to_char(PADATEOFJOININGD,'YYYY'), count(*)

from PAEMPLOYEE_M

group by (to_char(PADATEOFJOININGD,'YYYY'))

union

select 'total emplyee', count(*)

from PAEMPLOYEE_M

 

  Was this answer useful?  Yes

baridbej

  • May 24th, 2008
 

SELECT COUNT(*) TOTAL_EMP,
SUM(CASE WHEN INSTR(HIREDATE,'81') > 0 THEN 1 ELSE 0 END)HIRED_81,
SUM(CASE WHEN INSTR(HIREDATE,'80') > 0 THEN 1 ELSE 0 END)HIRED_80,
SUM(CASE WHEN INSTR(HIREDATE,'87') > 0 THEN 1 ELSE 0 END)HIRED_87,
SUM(CASE WHEN INSTR(HIREDATE,'82') > 0 THEN 1 ELSE 0 END)HIRED_82
FROM EMP
/

This query is as per ORACLE 9I EMP table that I have in my home.

  Was this answer useful?  Yes

lanka_satya

  • Sep 12th, 2008
 

select count(*) Count, to_char(hiredate, 'YYYY') YEAR from emp group by to_char(hiredate, 'YYYY') having substr(to_char(hiredate,'yyyy'),-1) in(5,6,7,8)

  Was this answer useful?  Yes

javedans

  • Jul 8th, 2009
 

Please check with this query...
SELECT COUNT(EMPID) TOTAL_EMPS,
       DECODE(TO_CHAR(HIRE_DATE,YYYY)),'1995',COUNT(EMPID)) TOTAL_HIRE_1995,
       DECODE(TO_CHAR(HIRE_DATE,YYYY)),'1996',COUNT(EMPID)) TOTAL_HIRE_1996,
       DECODE(TO_CHAR(HIRE_DATE,YYYY)),'1997',COUNT(EMPID)) TOTAL_HIRE_1997,
       DECODE(TO_CHAR(HIRE_DATE,YYYY)),'1998',COUNT(EMPID)) TOTAL_HIRE_1998
FROM EMP

emraan

  • Dec 28th, 2009
 

select count(*), count(decode(to_char(hiredate, 'yyyy'), 1995,1)), 
                count(decode(to_char(hiredate, 'yyyy'), 1996,1)),
                count(decode(to_char(hiredate, 'yyyy'), 1997,1)),
                count(decode(to_char(hiredate, 'yyyy'), 1998,1)) from emp

Venkadesh Raja

  • Jan 19th, 2012
 

Code
  1.  

  Was this answer useful?  Yes

P.R.KHUNTIA

  • Mar 19th, 2012
 

Code
  1.  

  Was this answer useful?  Yes

Sudarsan

  • Mar 14th, 2013
 

SELECT Hiredate,Count(*)
FROM emp
WHERE to_char(hiredate,yyyy) in (1995,1996,1997,1998)
GROUP BY Hiredate;

  Was this answer useful?  Yes

D.Venkat

  • Oct 31st, 2013
 

SELECT to_char(hiredate,YYYY),count(*) FROM employee GROUP BY to_char(hiredate,YYYY);

  Was this answer useful?  Yes

RAVI

  • Dec 8th, 2015
 

Code
  1.  

  Was this answer useful?  Yes

Ashish

  • Apr 30th, 2016
 

This query we can write many ways, I will give two solution
1. By using UNION ALL operator
2. By using sub query

Code
  1.  

  Was this answer useful?  Yes

kinza

  • Oct 21st, 2016
 

What if we want to display list of salaries per year in last 20 years?

  Was this answer useful?  Yes

Mercy

  • Oct 29th, 2018
 

Hope the below query will answer the question.

Code
  1. span style="color: #ff0000;">"1995""1996""1997""1998"

  Was this answer useful?  Yes

shital Rathod

  • Nov 24th, 2021
 

this solution best in oracle ,but decode () is not work in mysql.
can you take in mysql and giv me the proper query regarding this question.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions