读书人

抉择列表中的列 #039;tb_masCustomer.Cust

发布时间: 2012-10-05 15:34:34 作者: rapoo

选择列表中的列 'tb_masCustomer.CustomerName' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
select c.CustomerName,
case when a.EwStatus = 'N' then '新入职'
when a.EwStatus = 'A' then '在职'
when a.EwStatus = 'W' then '离职办理中'
when a.EwStatus = 'L' then '已离职' end as State,
case when e.GenderID = 2 then '女'
when e.GenderID = 1 then '男' end as Gender,
count(*) as Sum
from tb_masEmployeeEmployer a
left join tb_masCustomer c on a.CustomerID = c.CustomerID
left join tb_masEmPersonalInfo e on a.EmPersonalInfoID = e.EmPersonalInfoID
where 1 = 1 and a.Disabled = 0 and e.GenderID is not null

[解决办法]
需要添加group by c.CustomerName

SQL code
select c.CustomerName,  case when a.EwStatus = 'N' then '新入职'  when a.EwStatus = 'A' then '在职'  when a.EwStatus = 'W' then '离职办理中'  when a.EwStatus = 'L' then '已离职' end as State,  case when e.GenderID = 2 then '女'when e.GenderID = 1 then '男' end as Gender,  count(*) as Sum  from tb_masEmployeeEmployer a  left join tb_masCustomer c on a.CustomerID = c.CustomerID  left join tb_masEmPersonalInfo e on a.EmPersonalInfoID = e.EmPersonalInfoID  where 1 = 1 and a.Disabled = 0 and e.GenderID is not null group by c.CustomerName 

读书人网 >SQL Server

热点推荐