Mysql 如何在“from”部分实现排序子查询?
在连接表之前,我需要对表进行子查询排序,以便在对表进行分组时,显示正确的折叠数据。对于示例查询,我想要给定日期时间2006-08-26 00:00:00之前的最新开始时间Mysql 如何在“from”部分实现排序子查询?,mysql,cakephp,subquery,Mysql,Cakephp,Subquery,在连接表之前,我需要对表进行子查询排序,以便在对表进行分组时,显示正确的折叠数据。对于示例查询,我想要给定日期时间2006-08-26 00:00:00之前的最新开始时间 select * from parts p left join (select * from transactions t left join transactiondetails td on(td.transaction_id=t.id and t.type='loc' and t.start<='2006-
select * from
parts p left join
(select * from
transactions t
left join
transactiondetails td
on(td.transaction_id=t.id and t.type='loc' and t.start<='2006-08-26 00:00:00')
order by start desc) t
on (t.part_id=p.id)
group by p.id
cakePHP可以做到这一点。如果没有,如果from子句中包含子查询的视图无法保存,我将如何运行这样的自定义查询?我还没有看到Cake支持嵌套查询。但是,您可以简单地将此查询原样传递到Model->query 我还没有看到Cake支持嵌套查询。但是,您可以简单地将此查询原样传递到Model->query 你能给我们一个你的样本数据和期望输出的例子吗?我得到期望输出。。。上面的查询没有错误,子查询无法消除。。。这是一个cakePHP问题…你能给我们一个例子,你的样本数据和期望的输出吗?我得到期望的输出。。。上面的查询没有错误,子查询无法消除。。。这是一个棘手的问题。。。