Select number of employees gender wise in each department

25 pts.
Tags:
relations
SQL
select number of employees gender wise in each department. In the employee table, gender of employees is stored whereas department number is stored in works_on table.

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • ToddN2000
    Sounds like a homework question. Show us what you have and we can help figure out any issues we have.
    15,060 pointsBadges:
    report
  • aamirsuhail
    Thanks for ur reply. Actually i did it. If u have other ways to do this, then reply with your query. This one worked for me:

    select works1.deptno,count(case when gender='Male' then 1 end)as male,count(case when gender='Female' then 1 end) as female from works1.deptno join employee on works1.empno=employee.empno group by works1.deptno;
    25 pointsBadges:
    report
  • aamirsuhail
    SQL> select works1.deptno,count(case when gender='Male' then 1 end) as male,count(case when gender='Female' then 1 end)as female from works1 join employee on works1.empno=employee.empno group by works1.deptno;

        DEPTNO       MALE     FEMALE
        ----------      ----------     ----------
             1                 1              2
             2                 4              0
             3                 0              4
    25 pointsBadges:
    report
  • carlosdl
    If you want the male and female counts in the same record, then that (or some variation of it) is how you need to do it.

    If that is not a requirement you could simply group by deptno and gender.

    70,200 pointsBadges:
    report
  • aamirsuhail
    Thanks for ur reply. I did 'group by deptno,gender'. That way it worked well.
    25 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following