nyc2
unread,Nov 8, 2011, 5:47:11 AM11/8/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to quer...@googlegroups.com
Hi,
I got stuck while trying to create a (relatively) complex query like this one:
select sub.col,sub.alias,count(*) from (
select distinct t.col1,(case when t.col2='...' then 1 else 0 end) alias, ... from QTable t join ... where ...
union
select distinct t.col1,(case when t.col2='...' then 1 else 0 end) alias, ... from QTable t join ... where ...
union ...
) sub
group by sub.alias, sub. ...
What I currently have is:
SQLSubQuery sub = new SQLSubQuery();
for(String str : strs) {
SQLSubQuery subUnion = new SQLSubQuery().from(Table).join(...).on(...).where(...);
PathBuilder<Object[]> subAlias = new PathBuilder<Object[]>(Object[].class, "sub");
Expression<Boolean> alias = new CaseBuilder().when(Table.col2.eq(...)).then(true).otherwise(false);
sub.union(subUnion.listDistinct(Table.col1, alias, ...)); // not available
}
query().from(sub, Path<?> alias).groupBy(sub.alias, sub. ...).list(sub.col, sub.alias, count(*)); // how to do this?
Could you please help me with this query? Thank you so much.