select * from road_detect_pqi a , (select roadid,startmile,endmile,max(detect_year) detect_year from road_detect_pqi
where roadid='G15'and startmile>='1865600.00' and endmile<='1866100.00'
group by startmile+endmile,startmile,endmile,roadid ) b
where a.roadid=b.roadid and a.startmile=b.startmile and a.endmile=b.endmile and a.detect_year=b.detect_year order by a.startmile+a.endmile
where roadid='G15'and startmile>='1865600.00' and endmile<='1866100.00'
group by startmile+endmile,startmile,endmile,roadid ) b
where a.roadid=b.roadid and a.startmile=b.startmile and a.endmile=b.endmile and a.detect_year=b.detect_year order by a.startmile+a.endmile
你语句这么长感觉用SQL比较合适,如果真要变成Hql的话,针对你所写的sql代码建议定义一个显示的VO类,写出相应的构造方法.
显示VO:ShowVo
road_detect_pqi:AModel如下(没经过实验的伪代码):
select 包名.ShowVo from AModel a,(select b.roadid,b.startmile,b.endmile,max(b.detect_year) detect_year from road_detect_pqi b
where b.roadid='G15'and b.startmile>='1865600.00' and b.endmile<='1866100.00'
group by b.startmile+b.endmile,b.startmile,b.endmile,b.roadid ) c
where a.roadid=b.roadid and a.startmile=c.startmile and a.endmile=c.endmile and a.detect_year=c.detect_year order by a.startmile+a.endmile
where b.roadid='G15'and b.startmile>='1865600.00' and b.endmile<='1866100.00'
group by b.startmile+b.endmile,b.startmile,b.endmile,b.roadid ) c
where a.roadid=b.roadid and a.startmile=c.startmile and a.endmile=c.endmile and a.detect_year=c.detect_year order by a.startmile+a.endmile其中定义的和以上的字段一致。