我需要獲得updatedtime
(最新)desc的前1條記錄訂單。我無法從我的表過濾器頂部1記錄如何使用linq在SQL Server中使用desc獲取每個組訂單的前1條記錄
select watertowerid, DOValue, PHValue, WaterTemperature, CurrentTime
from ParkingSlots
group by watertowerid, PHValue, DOValue, WaterTemperature, CurrentTime
的樣本數據:
PHValue DOValue WaterTemperature watertowerid CurrentTime
---------------------------------------------------------------------------
3.00 4.00 22.00 1 2016-09-29 02:34:00
6.00 4.00 33.00 2 2016-11-29 02:34:00
8.22 6.55 28.22 1 2016-06-25 01:25:00
30.52 5.60 27.00 2 2016-08-29 02:34:00
所需的輸出:
PHValue DOValue WaterTemperature watertowerid CurrentTime
---------------------------------------------------------------------------
3.00 4.00 22.00 1 2016-09-29 02:34:00
6.00 4.00 33.00 2 2016-11-29 02:34:00
你有什麼想法如何在LINQ中寫這個查詢 – Swapna
Linq沒有直接的模擬。請參閱此主題的選項http://stackoverflow.com/questions/22157211/linq-to-entities-equivalent-of-sql-topn-with-ties – Serg