這裏是我想要轉換成的LINQ查詢:我如何轉換這個SQL查詢到LINQ(OVER(PARTITION BY日期))
SELECT R.Code,
R.FlightNumber,
S.[Date],
S.Station,
R.Liters,
SUM(R.Liters) OVER (PARTITION BY Year([Date]), Month([Date]), Day([Date])) AS Total_Liters
FROM S INNER JOIN
R ON S.ID = R.SID
WHERE (R.Code = 'AC')
AND FlightNumber = '124'
GROUP BY Station, Code, FlightNumber, [Date], Liter
ORDER BY R.FlightNumber, [Date]
感謝您的幫助。
更新:這是我正在嘗試的Linq代碼;我無法按日期進行OVER PARTITION。
var test =
(from record in ent.Records join ship in ent.Ship on record.ShipID equals ship.ID
orderby ship.Station
where ship.Date > model.StartView && ship.Date < model.EndView && ship.Station == model.Station && record.FlightNumber == model.FlightNumber
group record by new {ship.Station, record.Code, record.FlightNumber, ship.Date, record.AmountType1} into g
select new { g.Key.Station, g.Key.Code, g.Key.FlightNumber, g.Key.Date, AmmountType1Sum = g.Sum(record => record.AmountType1) });
你到目前爲止嘗試過什麼? Stackoverflow不是一個網站,您只需發佈內容並告訴人們「修復它」或「轉換此」,因此在將來您提出問題時,請考慮一下。 – Joakim
請看更新。 –
根據我的經驗,我發現linqer是將t-sql轉換爲linq的非常有用的工具。 http://www.sqltolinq.com/ - 帶有10天免費試用版。 –