I have a query like below
select field1,filed2,count(*),
sum(case isNew WHEN 0 THEN 0 ELSE 1 END) as new_count1,
sum(case source WHEN 'SomeValue' THEN 0 ELSE 1 END) as new_count2
from TABLE
where status='processed'
and filed1='filed1Value'
and filed2='field2Value';
The output of this is a single row containing all values I require. I want to achieve the same using queryDSL. I am using the CaseBuilder in the QueryDSL but unable to apply sum on top of it.. Does QueryDsl support that? Any one solved this before??
Expression<Integer> sourceCases = qTable.source.
when(matchedValue1).then(new Integer(1)).
otherwise(new Integer(0));
Expression<Integer> newAccountCases = qTable.isNew.
when(matchedValue2).then(new Integer(1)).
otherwise(new Integer(0));
return queryDslJdbcTemplate.queryForObject(sqlQuery,
new Mapping(qTable.filed1,
qTable.filed2,
qTable.id.count(),
####SUM( (sourceCases) )###,
####SUM( (newAccountCases) )###);