Web Development



I need some sql query pivot help

By Postonoh ·
SELECT top(10000)
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 conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Two queries and then maybe a third to join

by Tony Hopkinson In reply to I need some sql query piv ...

them up.
Sum by day
then sum by month of the day basically
after all the month totals will be repeated for every day even if you could do it there.
Same query but change
p.Date in the group by clause to something like
group by DatePart(month,p.date) deoending on waht flavour of sql you are using.

Related Discussions

Related Forums