JAVA Hibernate别名排序问题

今天在做统计功能的时候遇到这样一个问题,由于查询结果为统计的数据,即使用了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

 

posted @ 2015-06-27 17:47  rubekid  阅读(348)  评论(0编辑  收藏  举报