表Test 字段(ID主键,WZMC,ShuLiang) 表中数据不止这两条数据,主要的用处是查询表中数据做个排行的,其中NO为自己as的,例如: NO WZMC ShuLiang
1 鼠标 500
2 鼠标 200合并后: NO WZMC ShuLiang
1 鼠标 700
我已写好的存储过程:
SELECT ROW_NUMBER() OVER (ORDER BY ShuLiang DESC) AS NO,WZMC,SUM(ShuLiang)AS ShuLiang FROM dbo.Test where 1=1
麻烦各位大虾在这基础上帮我改下,谢啦
1 鼠标 500
2 鼠标 200合并后: NO WZMC ShuLiang
1 鼠标 700
我已写好的存储过程:
SELECT ROW_NUMBER() OVER (ORDER BY ShuLiang DESC) AS NO,WZMC,SUM(ShuLiang)AS ShuLiang FROM dbo.Test where 1=1
麻烦各位大虾在这基础上帮我改下,谢啦
SELECT ROW_NUMBER() OVER (ORDER BY ShuLiang DESC) AS NO,
WZMC,
SUM(ShuLiang)AS ShuLiang FROM dbo.Test
group by WZMC
GROUP BY WZMC
(select WZMC,SUM(ShuLiang) as ShuLiang from Test group by WZMC) as a
错误信息为:
Msg 8120, Level 16, State 1, Line 1
Column 'dbo.Test.ShuLiang' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Line 1
Column 'dbo.Test.ShuLiang' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
ID int,
WZMC nvarchar(50),
ShuLiang int