Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query to find certain data Expand / Collapse
Author
Message
Posted Tuesday, May 14, 2013 11:57 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 19, 2013 3:34 AM
Points: 4, Visits: 23
Hello i stumbled upon task to do write query that will count all employees from employees table but also will count employees hired (hire_date is a column name) in given years 1995 and 1996.

So as a result i should get:

Column 1 ( all employees) | Column 2 ( those hired in 1995 ) | column 3 (those hired in 1996)
-----------------------------------------------------------------------------------------
Value 1 Value 2 Value 3


Any suggestions how to get it?
Post #1452752
Posted Tuesday, May 14, 2013 12:36 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 2:59 AM
Points: 1,887, Visits: 18,576
as a guide


SELECT COUNT(employee) AS All_cnt,
sum(case when hiredate = '1995' then 1 else 0 end) as HY_1995 ,
sum(case when hiredate = '1996' then 1 else 0 end) as HY_1996
FROM employees




__________________________________________________________________
you can lead a user to data....but you cannot make them think !
__________________________________________________________________
Post #1452768
Posted Tuesday, May 14, 2013 12:40 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 19, 2013 3:34 AM
Points: 4, Visits: 23
Thank you!
Post #1452772
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse