1
select *
from monthStatistics ms
where ms.beloneMonth =
(
select max(ms2.beloneMonth)
from monthStatistics ms2
where ms.materialDictionaryId = ms2.materialDictionaryId
and ms.locationId = ms2.locationId
and ms.price=ms2.price
)
id beloneMonth materialDictinaryId price acount
1 2013/7 1 100 200
2 2013/7 2 100 200
3 2013/8 1 100 200
4 2013/8 1 200 200
結果:
id beloneMonth materialDictinaryId price acount
2 2013/7 2 100 200
3 2013/8 1 100 200
4 2013/8 1 200 200
組,並獲得最高月份行。
你給不真正顯示你正在嘗試做的SQL返回其具有
max
價值monthStatistics
行(S)。我們需要首先修復你的SQL,然後我們需要轉換爲Linq。 – Aron您可以查看我的編輯。你需要的是Group By'id',然後得到每個'id'具有最大'beloneMonth'的行。 –