2015-02-07 52 views
2

我想在遊戲框架中使用Group By。請問有人能告訴我如何使用Group By play框架?如何在遊戲框架中使用Group By?

+0

你的意思斯卡拉GROUPBY,或SQL 「分組依據」?請提供您正在嘗試執行的操作以及迄今爲止所嘗試的內容的其他詳細信息。 – wwkudu 2015-02-07 04:16:06

+0

SQL「group by」。我正在閱讀文檔的播放框架。 我想'find.where()。groupBy(「fieldname」)。findList()'。但是,我沒有找到像「groupBy」這樣的方法。 – offee 2015-02-07 04:27:05

回答

0

使用GroupByEbean中的一種方法是使用SqlQuery

// Necessary imports.. 
import com.avaje.ebean.Ebean; 
import com.avaje.ebean.Query; 

// SQL query. 
String sql = "select max(salary) as maximum_salary, min(salary) as minimum_salary, department_id from employee_details where joining_date > :date group by department_id"; 

// Will get the list of Sql rows. 
List<SqlRow> sqlRows = Ebean.createSqlQuery(sql).setParameter("date", "1995-10-21").findList(); 

// Getting first row of the list 
SqlRow sql_row = sqlRows.get(0); 

// Getting values of respective columns by using their name 
int maximumSalary = sql_row.getInteger("maximum_salary"); 
int minimumSalary = sql_row.getInteger("minimum_salary"); 
int departmentID = sql_row.getInteger("department_id"); 
0

您可以運行前rawsql

String sql 
    = " select order_id, o.status, c.id, c.name, sum(d.order_qty*d.unit_price) as totalAmount" 
    + " from o_order o" 
    + " join o_customer c on c.id = o.kcustomer_id " 
    + " join o_order_detail d on d.order_id = o.id " 
    + " group by order_id, o.status "; 

RawSql rawSql = 
    RawSqlBuilder 
     // let ebean parse the SQL so that it can 
     // add expressions to the WHERE and HAVING 
     // clauses 
     .parse(sql) 
     // map resultSet columns to bean properties 
     .columnMapping("order_id", "order.id") 
     .columnMapping("o.status", "order.status") 
     .columnMapping("c.id",  "order.customer.id") 
     .columnMapping("c.name", "order.customer.name") 
     .create(); 


Query<OrderAggregate> query = Ebean.find(OrderAggregate.class); 
    query.setRawSql(rawSql)   
    // add expressions to the WHERE and HAVING clauses 
    .where().gt("order.id", 0) 
    .having().gt("totalAmount", 20); 

List<OrderAggregate> list = query.findList(); 

注意:不要忘了進口com.avaje.ebean *;

Source