sum all rows after group by

57 views
Skip to first unread message

rohith reddy

unread,
Nov 27, 2016, 3:25:26 AM11/27/16
to Querydsl
Hello, i am trying to sum rows of table after group by, let me explain my problem with an example:
example: from table below....
1. i need to calculate total expenses by name, dept. I can do this with group by , simple and easy.
 by name:
 select e.Employee name , sum(expenses) from Employee e group by Employee name
by dept:
select e.Employee name , sum(expenses) from Employee e group by dept
2. this is where i am struggling with query dsl.  i need to calculate total expenses when grouped by name  or dept. with native sql i can do below
select sum(employeeExpense) from (select e.Employee name , sum(expenses) as employeeExpense from Employee e group by Employee name)X

I am stuck with step 2 to solve that problem using  query dsl, is there a way to do this in query dsl ?


Employee:


Employee name

expenses

dept

John

200

1

Karen

300

1

Jessica

500

2

John

100

1

karen

50

1


thanks for your time.

Franco Bellucci

unread,
Feb 3, 2017, 8:30:18 AM2/3/17
to Querydsl
I'm looking for the same answer. I can't find examples with aggregate functions like sum or avg. 
Any example would be great

Thanks
Reply all
Reply to author
Forward
0 new messages