0

I'm new to SQL fiddling with JOINS & failing to get the outcome. Any help would be truly appreciated.

Requirement

I've got a table, DATA1 & a copy of it called DATA2. The columns in it are EMPID,JOINING_DATE,DESIGNATION,COMMENTS,GENDER,DEPARTMENT

I've got VB code which selects data from the excel sheet containing the above 2 sheets using ADO. When I run a query say, get me the count of number of employees who joined IT department every month between 01/2011 & 03/2011, I expect to see result similar to the below

01/2011 0
02/2011 1
03/2011 0

Sample Data

I've created sample data below

1|01/2011|AAA|DG1|asdasdasd|Male|Sales
2|01/2011|BBB|DG1|asdasdasd|Female|Networking
3|02/2011|AAA|DG7|asdasdasd|Male|Sales
4|02/2011|AAA|DG5|asdasdasd|Female|IT
5|03/2011|AAA|DG1|asdasdasd|Male|MArketing

Please can someone help me here?

1 Answer 1

1

Assuming you have someone who started in each month:

select year(joining_date), month(joining_date),
       sum(case when department = 'IT' then 1 else 0 end)
from sample 
group by year(joining_date), month(joining_date)
order by 1, 2;
Sign up to request clarification or add additional context in comments.

2 Comments

Hello Gordon,Thanks for this. With ADO, "when" doesn't work. I've looked around for workarounds but can't get anything that works. Is there an alternate for this please?
What database are you using?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.