在用于 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 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