I need some sql query pivot help - TechRepublic
Question
May 10, 2011 at 10:42 AM
postonoh

I need some sql query pivot help

by postonoh . Updated 15 years, 1 month ago

SELECT top(10000)
p.Date,
p.Project_ID,
sum(case when p.Minority = ‘Yes’ then 1 else 0 end) as ‘Total Minority’,
sum(case when p.Gender = ‘Female’ then 1 else 0 end) as ‘Total Female’,
sum(case when p.Cleveland_Resident = 1 then 1 else 0 end) as ‘Cleveland Resident’,
sum(case when p.Minority = ‘Yes’ or p.Minority =’No’ and p.Gender = ‘Female’ or p.Gender = ‘Male’ then 1 else 0 end) as ‘Total Employees’
FROM PersonnelSummary p
group by p.Minority, p.Date, p.Project_ID, p.Gender, p.Cleveland_Resident
order by p.Date, p.Project_ID asc

I have this view which display. I am trying to have the view sum each date in one column then sum total minority for the month, total female for the month and so on per project_id. Any suggestions

This discussion is locked

All Comments