日期:2014-05-17  浏览次数:20599 次

选择列表中的列 '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