相关疑难解决方法(0)

Grails使用executeQuery()计算算术表达式?

我需要得到每个商店每个订单销售的所有商品的总和.我正在使用executeQuery()在表达式上运行sum().它工作得很好,如下所示,但我想知道是否有更好,更时髦的方法来做到这一点.

StoreService {
  static transactional = false

  def getTotalOrders(def store) {
    return Store.executeQuery("select sum(a.soldQuantity * a.soldPrice) as total 
             from OrderItem a inner join a.order b inner join b.store c 
             where c= :store", [store: store]).get(0)
  }
}

Store {
  transient storeService

  def getTotalSales() {
    storeService.getTotalSales()
  }

  static hasMany = [items: Item]
  // no hasMany to Order
}

Item {
  static belongsTo = [store: Store]
  // no hasMany to OrderItem
}


Order {
  static hasMany = [orderItems: OrderItem]
  static belongsTo = [store: …
Run Code Online (Sandbox Code Playgroud)

grails grails-orm

2
推荐指数
1
解决办法
4139
查看次数

标签 统计

grails ×1

grails-orm ×1