select CONTRACT_ID, sum(PO_SPEND)
from V_CONTRACT_ANALYSIS_202
group by CONTRACT_ID
order by sum(PO_SPEND) desc
views:
192answers:
1
+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
2010-01-07 08:15:18
Oracle, Informix, MySQL, DB2, and SQL Server all allow it, at least in recent versions.
Brian Deterling
2010-01-07 14:43:58