These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: selecting from nested queries
PostPosted: Fri Mar 18, 2011 12:48 am 
Newbie

Joined: Fri Mar 18, 2011 12:42 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.