我有疑问。我想用一个表(没有连接或其他)做子查询。我有那个SQL代码:
select * from
(select * from eksplikacja order by id DESC)
t group by ble
但我不知道如何在CakePHP 3查询ORM中做到这一点。 你能救我吗?
答案 0 :(得分:2)
使用查询构建器而不访问任何模型
$connection = \Cake\Datasource\ConnectionManager::get('default');
$subquery = $connection
->newQuery()
->select('*')
->from('eksplikacja')
->order(['id' => 'DESC']);
$query = $connection
->newQuery()
->select('*')
->from(['t' => $subquery ])
->group(['ble']);