I have a requirement which is somewhat similar to this. My API supports a filter where there is more than 8 filter parameter. So, I want to create a query dynamically based on the filter parameter passed. I am using CriteriaBuilder
to create a dynamic query.
Now, I am able to create dynamic queries successfully but the issue comes when the user wants to sort on an aggregate
functions. In my query, I have 4 aggregate (count) function. So to support sorting on these columns, I just use the expression
of this aggregate function but what I want is to use the alias
of this expression
Repeating the expression
in select
and order by
doesn't seem right to me. So, is there a solution/workaround to the problem. I want to declare the expression alias
once and use it in both select
and order by
clause and if required in my group by
clause in future