【发布时间】:2026-01-19 06:55:02
【问题描述】:
SELECT * FROM
(SELECT post.* FROM post ORDER BY post.timestamp DESC) as post
GROUP BY post.topic_id
ORDER BY post.timestamp DESC, post.position
LIMIT 15
Phalcon 在尝试执行上述查询时抛出以下错误。查询本身在默认 sql 上运行良好。
Syntax error, unexpected token (, near to ' SELECT post.* FROM post ORDER BY post.timestamp DESC ) as post GROUP BY post.topic_id ORDER BY post.timestamp DESC, post.position LIMIT 15', when parsing: SELECT * FROM ( SELECT post.* FROM post ORDER BY post.timestamp DESC ) as post GROUP BY post.topic_id ORDER BY post.timestamp DESC, post.position LIMIT 15 (162)
使用以下 PHP 代码(用于测试):
$sql = <<< QUERY
*query*
QUERY;
$query = $this->modelsManager->createQuery($sql);
$result = $query->execute();
感谢您的帮助。
【问题讨论】:
-
使用子查询不会那么好。查看this article on selecting the one row per group。
-
我去看看。谢谢!