Hi all i have a problem selecting from a nested query. I need to do it this way as the where clause is being generated dynamically at run time using hibernate filters. here is the query.
select com.channel_count,sum(com.order_count), sum(com.order_revenue), sum(com.order_margin) from ( select cm.customer.id, count(DISTINCT cm.channel.id) as channel_count, sum(cm.orderCount) as order_count, sum(cm.totalRevenue) as order_revenue, sum(cm.totalMargin) as order_margin from CustomerOrderCountMonthly as cm group by cm.customer.id) as com group by com.channel_id
unfortunately its giving a syntax error on the red parenthesis. I have seen other answers suggesting to use inner joins and such but I really can't see how to do it in my case. The problem is I need to group by the nested queries aggregate. And I won't know how its aggregating until runtime and the user selects the filters.
|