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

在用于 GROUP BY 子句分组依据列表的表达式中,不能使用聚合或子查询。该怎么解决

2012-06-07 
在用于 GROUP BY 子句分组依据列表的表达式中,不能使用聚合或子查询。create procedure ListSaleSum@year i

在用于 GROUP BY 子句分组依据列表的表达式中,不能使用聚合或子查询。
create procedure ListSaleSum
@year int,
@month int
as
begin
select sale.empid as 员工编号,
employee.empname as 员工姓名,
sum(salesum) as 销售合计
from sale,employee
where sale.empid=employee.empid
and year(saledate)=@year
and month(saledate)=@month
group by sale.empid,employee.empname,sum(salesum)
end

消息 144,级别 15,状态 1,过程 ListSaleSum,第 6 行
在用于 GROUP BY 子句分组依据列表的表达式中,不能使用聚合或子查询。

怎么改啊?

[解决办法]

SQL code
group by sale.empid,employee.empname--,sum(salesum)
[解决办法]
SQL code
create procedure ListSaleSum@year int,@month intasbegin    select         sale.empid as 员工编号,        employee.empname as 员工姓名,        sum(salesum) as 销售合计    from sale,employee    where sale.empid=employee.empid    and year(saledate)=@year    and month(saledate)=@month    group by sale.empid,employee.empname        --,sum(salesum) 这里不需要的end 

热点排行