当前位置: 代码迷 >> Sql Server >> 抉择列表中的列 'tb_masCustomer.CustomerName' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中
  详细解决方案

抉择列表中的列 'tb_masCustomer.CustomerName' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中

热度:69   发布时间:2016-04-27 11:34:43.0
选择列表中的列 '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
  相关解决方案