sql语句为select * from (select location_id,region_code,county_name,count(region_code) as countKKou from mon_location where longitude !=0.0 and region_code in ('370901') GROUP BY region_code) as teb LEFT JOIN mon_region as r on teb.region_code = r.code ;
求hql语句
其中sql
select location_id,region_code,county_name,count(region_code) as countKKou from mon_location where longitude !=0.0 and region_code in ('370901') GROUP BY region_code
已经转化为select new com.yisa.map.domain.LocationLocation(m.location_id,count(m.region_code) as countKKou,m.region_code,m.county_name) from LocationVo as m where m.longitude !=0.0 and m.region_code in ('370901') GROUP BY m.region_code

sql语句转hibernate hql语句
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 你知我知皆知 2024-08-05 01:13关注
以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
你可以使用Hibernate的
map
和join
方法来将SQL查询转换为HQL查询。以下是一个例子:@MappedStatement( statement = "mon_location", resultSetMapping = { @Result(property="location", column="location_id"), @Result(property="countRegionCode", column="region_code"), @Result(property="countRegionCount", column="count(region_code)") } ) public class MonLocation { @Query(value = "SELECT new com.yisa.map.domain.LocationLocation(m.location_id,count(m.region_code) as countKKou,m.region_code,m.county_name) FROM LocationVo AS m WHERE m.longitude != 0.0 AND m.region_code IN ('370901') GROUP BY m.region_code", nativeQuery = true) public List<LocationLocation> getLocationByRegionCode(@Param("longitude") double longitude, @Param("regionCode") String regionCode); @Join("getLocationByRegionCode") private Join<MonLocation, MonRegion> join; }
在这个例子中,我们首先创建了一个名为
mon_location
的映射,它返回一个包含三个属性的新对象:locationId
、countRegionCode
和countRegionCount
。然后我们在getLocationByRegionCode
方法中调用了这个映射,并传入了longitude
和regionCode
作为参数。请注意,你需要根据你的数据库表结构调整
mon_location
和MonRegion
类以及它们的字段名称。解决 无用评论 打赏 举报