Subquery in ebean

150 Views Asked by At

I am faced with the problem of forming subqueries in ebean. I need to compose a query that is similar to the following sql:

select sum(money), count(name) from (
    select owr."clientName" as name, owr."sumOfMoney" as money from nm."OrderWorkReport" owr) ff; 

This request is just an example, but it reflects the essence of the problem. I need to compose a select query from a select query.

I studied the ebean sources and documentation, but I didn't find an answer! Maybe someone has encountered this and knows how to write this select query using the ebean interfaces in java.

1

There are 1 best solutions below

0
Omar Hussien On

you can use sqlQuery in ebean see sqlQuery :

String sql = "select sum(ff.money) as sum, count(ff.name) as count from (\r\n"
            + "select owr.clientName as name, owr.sumOfMoney as money from OrderWorkReport owr) ff ;";
SqlRow row = DB.sqlQuery(sql).findOne();
int count= row.getInteger("count");
int sum =row.getInteger("sum");
System.out.println("sum = "+sum+"\ncount = "+count);