首页 > 编程语言 > 详细

JAVA Hibernate别名排序问题

时间:2015-06-27 18:06:52      阅读:243      评论:0      收藏:0      [点我收藏+]

今天在做统计功能的时候遇到这样一个问题,由于查询结果为统计的数据,即使用了sum方法生成的字段,

select refDate,sum(triggerCount) as triggerCount,sum(case when unique_key is null then 0 else trigger_count end) as hitCount from TriggerStatistic where user=:user and type=:type and refDate >=:fromDate and refDate <=:toDate group by refDate order by hitCount asc

会提示 TriggerStatistic不存在 hitCount 属性

于是使用查询的列序号进行排序

查询的列有

1:refDate

2:triggerCount

3:hitCount

要对hitCount这一列进行排序 只要使用 order by 3 asc/desc

于是改为:

select refDate as refDate,sum(triggerCount) as triggerCount,sum(case when unique_key is null then 0 else trigger_count end) as hitCount from TriggerStatistic where user=:user and type=:type and refDate >=:fromDate and refDate <=:toDate group by refDate order by 3 asc

 

JAVA Hibernate别名排序问题

原文:http://www.cnblogs.com/rubekid/p/4604363.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!