views:

192

answers:

1
select CONTRACT_ID, sum(PO_SPEND)
from   V_CONTRACT_ANALYSIS_202
group by  CONTRACT_ID 
order by  sum(PO_SPEND) desc
+1  A: 

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.

beltorak
Oracle, Informix, MySQL, DB2, and SQL Server all allow it, at least in recent versions.
Brian Deterling