日期:2014-05-17 浏览次数:20551 次
select CustomerName,c.CustomerID ,Sum(case when b.GenderID=1 then 1 else 0 end) as Boys ,Sum(case when b.GenderID=2 then 1 else 0 end) as Boys from tb_masEmPersonalInfo b join tb_masEmployeeEmployer a on b.EmpersonalInfoID=a.EmpersonalInfoID join tb_masCustomer c on a.CustomerID=c.CustomerID where a.EwStatus in ('A','N') group by c.CustomerName,c.CustomerID
------解决方案--------------------
select * from (select CustomerName,c.CustomerID,sum(case when b.GenderID=1 then 1 else 0 end ) as Boys,sum(case when b.GenderID=2 then 1 else 0 end ) as Girls, from tb_masEmPersonalInfo b join tb_masEmployeeEmployer a on b.EmpersonalInfoID=a.EmpersonalInfoID join tb_masCustomer c on a.CustomerID=c.CustomerID where a.EwStatus in ('A','N') group by c.CustomerName,c.CustomerID)