Hi @Newbie Newbie ,
Welcome to the microsoft TSQL Q&A forum!Your question is related to tsql, so my colleague helped you add the tsql tag.
Please also check:
CREATE TABLE #tblemp([Emp ID] INT, empname VARCHAR(25),joindate DATE,gender VARCHAR(25))
INSERT INTO #tblemp VALUES
(101,'Steve','01-01-2021','male'),
(102,'john','01-23-21','male'),
(103,'steffy','01-14-21','female')
SELECT year(joindate) as joinyr,
month(joindate) as joinmth,
count(*) as totalcount,
count(iif(gender='male',1,null)) malecount,
count(iif(gender='female',1,null)) femalecount
FROM #tblemp
GROUP BY year(joindate), month(joindate)
Output:
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.