开发者

Using Hibernate to 'order by' a column which having a expression(sum, max, ...)?

开发者 https://www.devze.com 2022-12-15 13:27 出处:网络
select CONTRACT_ID, sum(PO_SPEND) fromV_CONTRACT_ANALYSIS_202 group byCONTRACT_ID order bysum(开发者_JAVA技巧PO_SPEND) desc
select CONTRACT_ID, sum(PO_SPEND)
from   V_CONTRACT_ANALYSIS_202
group by  CONTRACT_ID 
order by  sum(开发者_JAVA技巧PO_SPEND) desc


From the hibernate docs

SQL functions and aggregate functions are allowed in the having and order by clauses if they are supported by the underlying database (i.e., not in MySQL).

It looks like you are using native SQL and not HQL however, but regardless of that you will need to check the database vendor docs to see if the DB supports ordering by an aggregated column. It looks correct though.

0

精彩评论

暂无评论...
验证码 换一张
取 消