2016-04-12 46 views

回答

2

首先嚐試在如何使用查詢生成器讀了ORM:

Query Builder - Aggregates Group and Having

這將是東西沿着這些線路

$query = $bookings->find(); 
$query->select([ 
    'count' => $query->func()->count('id'), 
    'total_price' => $query->func()->sum('price') 
])->where(['id' => 3]); 

計數將來自結果的數量,或者是附加在計數查詢生成器!

+0

它的工作。 謝謝。 – sradha

+0

我如何獲取數據? – sradha

+0

其全部內容在文檔中:http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html – Voycey