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.
| Author |
Topic |
|
shaaquille
Starting Member
4 Posts |
Posted - 2009-09-12 : 23:52:16
|
| hii 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,1982out put shd be like thistotal -- 1980 -- 1981 -- 1982 -- 198314 ----- 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] |
 |
|
|
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 likeSELECT 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 1983FROM Employee |
 |
|
|
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 likeSELECT 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 1983FROM Employee The function YEAR wont work in Oracle. It should be to_char(HiringDate,'yyyy')=1980
MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|