例如,我有一个表:
id | number
-----------
1 | 1
2 | 1
3 | 1
4 | 2
5 | 2
6 | 3我需要计算唯一的number (1,2和3),也就是3
我有可用的SQL代码:
SELECT COUNT(DISTINCT `number`) AS `total` FROM `some_table`但是我不知道如何用PHPActiveRecord更好地做到这一点
发布于 2013-02-23 00:11:41
phpAR中有一个count()函数,但不能让它与DISTINCT一起工作。所以,我认为最简单的方法是:
$total = SomeModel::first(['select' => 'COUNT(DISTINCT `number`) AS `total`'])->total;https://stackoverflow.com/questions/15026636
复制相似问题