New to SQL, using MS SQL Sever Management Studio with AdventureWorks sample DB:
Trying to combine two SELECT
statements each containing a COUNT
of Male and Female Employees.
I can get both counts to return two rows on the same table using UNION ALL.
SELECT COUNT(HumanResources.Employee.Gender) AS 'Male Employees'
FROM HumanResources.Employee
WHERE Employee.Gender = 'M'
UNION ALL
SELECT COUNT(HumanResources.Employee.Gender) AS 'Female Employees'
FROM HumanResources.Employee
WHERE Employee.Gender = 'F';
However I'm trying to get the COUNT
of each M/F in two separate columns. Managed to get two separate columns to appear but the counts are not there.
SELECT Set1.[Male Employees], Set2.[Female Employees]
FROM
(
SELECT COUNT(Employee.Gender) AS 'Male Employees'
FROM HumanResources.Employee
WHERE Employee.Gender = 'M'
) as Set1
INNER JOIN
(
SELECT COUNT(Employee.Gender) AS 'Female Employees'
FROM HumanResources.Employee
WHERE Employee.Gender = 'F'
) as Set2
on Set1.[Male Employees] = Set2.[Female Employees]
I feel like I'm missing something obvious..