1
我有一個使用子查詢的CakePHP查詢。雖然我發現了一些文檔,告訴我如何在Cake中使用子查詢來查找條件,但我一直無法找到將子查詢用作表的方法。CakePHP從子查詢中選擇(從SELECT(...)中選擇foo)
換句話說,我想表達的東西是這樣的:
SELECT `Status`.`name`,
COUNT(*) as total_count,
COUNT(NULLIF(over_one_year, 0)) as over,
COUNT(NULLIF(over_one_year, 1)) as under
FROM (
SELECT ((YEAR('##some date##') - YEAR(COALESCE(start_date, '1900-01-01'))) -
(RIGHT(DATE('##some date##'), 5) < RIGHT(COALESCE(start_date, '1900-01-01'), 5))
>= 1) as over_one_year,
status_id FROM `users` WHERE `user_id` IN (##some list of ids##)) as User
LEFT JOIN `statuses` AS `Status` ON (`User`.`status_id` = `Status`.`id`)
GROUP BY id;
蛋糕。
有沒有希望?