我有以下关联
用户拥有多个域名
域名有很多访问者
域名包含多个网页浏览量
以下是查询
SELECT
pv.name,pv.domain_id,pv.counter as page_visits, v.ip, v.counter as visits
FROM (
SELECT `domains`.`name` , `pageviews`.`domain_id` , COUNT( `pageviews`.`domain_id` ) as counter
FROM `pageviews`
LEFT JOIN `domains` ON ( `domains`.`id` = `pageviews`.`domain_id`
AND `domains`.`user_id` = '129' )
WHERE `pageviews`.`user_id` = '129'
GROUP BY `pageviews`.`domain_id`
ORDER BY COUNT( `pageviews`.`domain_id` ) DESC
) as pv
LEFT JOIN (
SELECT `domains`.`name` , `visitors`.`ip` , `visitors`.`domain_id` , COUNT( `visitors`.`domain_id` ) as counter
FROM `visitors`
LEFT JOIN `domains` ON ( `domains`.`id` = `visitors`.`domain_id`
AND `domains`.`user_id` = '129' )
WHERE `visitors`.`user_id` = '129'
GROUP BY `visitors`.`domain_id`
ORDER BY COUNT( `visitors`.`domain_id` ) DESC
) as v
ON pv.domain_id = v.domain_id
我想转换为cakephp查找paginate的查询,因为cakephp不允许$ this-> paginate(“mysql query here”);
答案 0 :(得分:1)
答案 1 :(得分:0)
您只需执行
查询即可$this->ModelName->query('your_sql_query');
这将为上面的复杂查询工作