Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 GROUP BY function

Author  Topic 

shaaquille
Starting Member

4 Posts

Posted - 2009-09-12 : 23:52:16
hi
i am newbie and i am preparing for oracle sql exam...
i am having problems with a query ... hope u kan help me :)
------------------------------------------
create a query that displays total number of employees...
and of that total number,number of emoloyees hired in 1980,1981,1982
out put shd be like this

total -- 1980 -- 1981 -- 1982 -- 1983
14 ----- 2------1 ------- 3 ------- 3

----------------------------------------------
thnx in advance
regards !

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-13 : 03:02:18
i can help you with query for MS SQL Server but not Oracle. You should post in an oracle forum like orafaq.com or dbforums.com


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-13 : 12:54:33
assuming your datefield is hiringdate and employee pk field is empno, it will something like


SELECT COUNT(EmpNo),
COUNT(CASE WHEN YEAR(HiringDate)=1980 THEN 1 ELSE 0 END) AS 1980,
COUNT(CASE WHEN YEAR(HiringDate)=1981 THEN 1 ELSE 0 END) AS 1981,
COUNT(CASE WHEN YEAR(HiringDate)=1982 THEN 1 ELSE 0 END) AS 1982,
COUNT(CASE WHEN YEAR(HiringDate)=1983 THEN 1 ELSE 0 END) AS 1983
FROM Employee
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-14 : 02:43:49
quote:
Originally posted by visakh16

assuming your datefield is hiringdate and employee pk field is empno, it will something like


SELECT COUNT(EmpNo),
COUNT(CASE WHEN YEAR(HiringDate)=1980 THEN 1 ELSE 0 END) AS 1980,
COUNT(CASE WHEN YEAR(HiringDate)=1981 THEN 1 ELSE 0 END) AS 1981,
COUNT(CASE WHEN YEAR(HiringDate)=1982 THEN 1 ELSE 0 END) AS 1982,
COUNT(CASE WHEN YEAR(HiringDate)=1983 THEN 1 ELSE 0 END) AS 1983
FROM Employee

The function YEAR wont work in Oracle. It should be to_char(HiringDate,'yyyy')=1980



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -