我正在使用实体框架我得到一个错误“”查询语法无效。近期':',第1行,第109列。“从系统.data.entity.sqlserver。所以请告诉我下面的查询转换成SQL将Mysal中的查询转换为SQL?
SELECT Agentid,year(Date_Time) as Year,monthname(Date_Time) as Month,SUM(AmountRecevied) as Amount,@rownum := @rownum + 1 AS Rank FROM collection_master,
(SELECT @rownum := 0) r GROUP BY AgentID,year(Date_Time),monthname(Date_Time) ORDER BY
Amount DESC
Agentid logintime AmountReceived
1 2013/10/01 00:10:10 10000
1 2013/10/01 17:23:10 200
1 2013/10/01 00:30:41 3000
2 2013/10/02 05:10:52 1000
3 2013/10/02 09:10:25 2000
3 2013/10/03 10:10:18 2000
2 2013/10/03 13:10:35 7000
我想应该显示输出
Agentid Amount Rank
1 13200 1
2 8000 2
3 4000 3
我曾尝试下面的查询没有得到查询预期的输出请检查一次
with temp as (
select row_number() over (order by AmountRecevied) as rownum,AgentID,YEAR(Date_Time) as Years,SUM(AmountRecevied) as amount
from tblcollections group by CustomerID,AgentID,Date_Time ,AmountRecevied
select rownum,AgentID,Years,amount from temp
您无法使用:将值分配给变量。 你想得到什么?查询的弊端是什么? – PeterRing
请检查我的eddited问题 – user123
SQL Server具有真正的窗口功能,不需要破解来生成一个rownumber。检查出'row_number()'函数 –