GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  RDBMS
Go To First  |  Previous Question  |  
 RDBMS  |  Question 18 of 18    Print  
Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.

  
Total Answers and Comments: 13 Last Update: November 06, 2009     Asked by: adnan 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
November 22, 2007 06:58:41   #1  
Chain Singh        

RE: Create a query that will display the total number ...
The query is:

select count(*) as Totalnoofemployees to_char(dateofjoining 'yyyy') as hiredyear from tablename
group by to_char(dateofjoining 'yyyy')

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
January 04, 2008 00:00:24   #2  
suganthi.m Member Since: December 2007   Contribution: 1    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.
select count(*) as Totalnoofemployees to_char(dateofjoining 'yyyy') as hiredyear from tablename
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
May 23, 2008 07:05:20   #3  
hemanth.6996 Member Since: May 2008   Contribution: 2    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.
select emp_id from employee_details group by emp_doj where emp_doj in (1980 1981 1982 1983);

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
November 12, 2008 02:07:35   #4  
dinu_26 Member Since: November 2008   Contribution: 5    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.
select count(*) as Totalnoofemployees to_char(dateofjoining 'yyyy') as hiredyear from tablename
 
Is this answer useful? Yes | No
January 21, 2009 17:58:39   #5  
mahen.12 Member Since: October 2008   Contribution: 1    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.

I think this is the query you are looking for !

select
count(*)
count(decode(to_char(hiredate 'YYYY') '1980' hiredate) ) "1980"
count(decode(to_char(hiredate 'YYYY') '1981' hiredate) ) "1981"
count(decode(to_char(hiredate 'YYYY') '1982' hiredate) ) "1982"
count(decode(to_char(hiredate 'YYYY') '1983' hiredate) ) "1983"
from emp ;


 
Is this answer useful? Yes | No
August 05, 2009 13:39:17   #6  
sqlnovice Member Since: August 2009   Contribution: 1    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.
I believe a small change to one of the answers already given here should give the desired results.

select count(*) as "Total Number of Employees"
count(decode(to_char(hiredate 'YYYY') '1980' empno) ) as "1980"
count(decode(to_char(hiredate 'YYYY') '1981' empno) ) as "1981"
count(decode(to_char(hiredate 'YYYY') '1982' empno) ) as "1982"
count(decode(to_char(hiredate 'YYYY') '1983' empno) ) as "1983"
from emp ;

 
Is this answer useful? Yes | No
August 06, 2009 04:56:15   #7  
vmvinod6 Member Since: August 2009   Contribution: 1    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.
select
count(*) tital
sum(decode(to_char(hire_date 'yyyy') '1981' 1 0)) "1981"
sum(decode(to_char(hire_date 'yyyy') '1982' 1 0)) "1982"
sum(decode(to_char(hire_date 'yyyy') '1983' 1 0)) "1983"
sum(decode(to_char(hire_date 'yyyy') '1984' 1 0)) "1984"
from employees;

 
Is this answer useful? Yes | No
August 13, 2009 11:52:44   #8  
gvmahesh Member Since: June 2009   Contribution: 3    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.
SELECT count(*) FROM emp where TO_CHAR(hiredate 'YYYY') in (1980 1981 1982 1983);
 
Is this answer useful? Yes | No
September 21, 2009 11:00:29   #9  
letsconverse Member Since: September 2009   Contribution: 1    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.
This one is better I guess:

query:

SELECT ((count(DECODE(to_char(hire_date 'YYYY') 1995 'c1')) )+(count(DECODE(to_char(hire_date 'YYYY') 1996 'c2')))+(count(DECODE(to_char(hire_date 'YYYY') 1997 'c3')))+(count(DECODE(to_char(hire_date 'YYYY') 1998 'c4')))) as TOTAL
count(DECODE(to_char(hire_date 'YYYY') 1995 'c1')) "1995"
count(DECODE(to_char(hire_date 'YYYY') 1996 'c2')) "1996"
count(DECODE(to_char(hire_date 'YYYY') 1997 'c3')) "1997"
count(DECODE(to_char(hire_date 'YYYY') 1998 'c4')) "1998"
FROM employees;

Results for the above query is like:

TOTAL 1995 1996 1997 1998
---------- ---------- ---------- ---------- ----------
65 4 10 28 23

Revert if you have a question. I'll try.
NOTE: You may want to change the spl characters and the years based on your requiremnet.

Thanks

 
Is this answer useful? Yes | No
September 23, 2009 13:27:13   #10  
gvmahesh Member Since: June 2009   Contribution: 3    

RE: Create a query that will display the total number of employees and of that total the number who were hired in 1980, 1981, 1982, and 1983. Give appropriate column headings.
using INLINE's

select ename sal job e1.noofemployees from emp
(select count(*) noofemployees from emp) e1 where to_char(hiredate 'YYYY') in (1980 1981 1982 1983);

using set operator:UNION

select nvl(to_char(null) 'no.of employees') empdetails
to_char(to_date(count(*) 'j') 'jsp') jobsalongwithnoofemployees from emp
union
select ename job from emp
where to_char(hiredate 'YYYY') in (1980 1981 1982 1983);

 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape