我正在使用實體框架我得到一個錯誤「」查詢語法無效。近期':',第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()'函數 –