Cod*_*rer 3 sql cakephp cakephp-3.0
我是CakePHP 3的新手,我想知道如何在COUNT之内使用DISTINCT,例如以下SQL查询。
SELECT `column_one`, COUNT(DISTINCT `column_two`) FROM `table` GROUP BY `column_one`
Run Code Online (Sandbox Code Playgroud)
你可以做
$query = $table->find()
->select([
'column_one',
'count' => "COUNT(DISTINCT `column_two`)"
])
->group(['column_one']);
Run Code Online (Sandbox Code Playgroud)
但是,如果您想使用cakephp sql函数,则可以执行
...
'count' => $query->func()->count('DISTINCT `column_two`')
....
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2334 次 |
| 最近记录: |