码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA Hibernate别名排序问题

时间:2015-06-27 18:09:29      阅读:148      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!