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
分组并获得最大月份行。