首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-10-05 
选择列表中的列 tb_masCustomer.CustomerName 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。sele

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

热点排行