0
SELECT AM.m, 
COUNT(JRC.id) FROM 
(SELECT 1 AS m 
   UNION ALL SELECT 2
   UNION ALL SELECT 3 
   UNION ALL SELECT 4 
   UNION ALL SELECT 5 
   UNION ALL SELECT 6
   UNION ALL SELECT 7
   UNION ALL SELECT 8
   UNION ALL SELECT 9
   UNION ALL SELECT 10
   UNION ALL SELECT 11
   UNION ALL SELECT 12
) AS AM
LEFT JOIN `candidates` AS `JRC`
ON   AM.m = MONTH(JRC.created) AND (JRC.jr_id = 58)
GROUP BY AM.m

这将导致 12 个月的每月明智用户计数

4

1 回答 1

0

取自这个答案:
CakePHP 2.1.x - Run a query without any models in AppController

$db = ConnectionManager::getDataSource('default');
$db->rawQuery($some_sql);

(另外,我建议您将此称为“派生表”而不是子查询。这似乎是一个微不足道的评论,但它可能会帮助您找到更适用的答案。)

于 2013-09-18T12:01:50.587 回答