Я даю вам базовое представление о том, что делать:
$a = TableRegistry::getTableLocator()->get('a', ['table' => 'TableA']); // use your table "TableA" as alias "a"
$query = $a->find();
$result = $query->select(['a.*']) // select all from table a
->select(['Last7DaysAmount' => $query->func()->sum('b.amount')]) // select sum('b.amount') AS Last7DaysAmount
->where(['b.date >' => DATE(NOW() - INTERVAL 7 DAY)]) // where b.date greater than current minus 7 days
->join([ // join other table
'table' => 'TableB',
'alias' => 'b',
'type' => 'left',
'conditions' => [ // with conditions
'a.client' => 'b.customer',
'a.vendor' => 'b.supplier',
'a.service' => 'b.service',
'a.country' => 'b.country',
]
])
->group([ // group results by
'a.client',
'a.vendor',
'a.service',
'a.country',
])
->order(['a.client' => 'ASC'])
->limit(100);
$this->set('results', $results);