Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PhalconPHP无法解析我的查询_Php_Mysql_Sql_Phalcon - Fatal编程技术网

PhalconPHP无法解析我的查询

PhalconPHP无法解析我的查询,php,mysql,sql,phalcon,Php,Mysql,Sql,Phalcon,Phalcon在尝试执行上述查询时抛出以下错误。查询本身在默认sql上运行良好 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 使用以下PHP代码(用于测试): $sql=createQuery($sql); $result=$query-

Phalcon在尝试执行上述查询时抛出以下错误。查询本身在默认sql上运行良好

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
使用以下PHP代码(用于测试):

$sql=createQuery($sql);
$result=$query->execute();
谢谢你的帮助

  • 创建视图,以保持已反向排序的虚拟表:

    创建查看v_latest_posts作为SELECT*从post ORDER按时间戳DESC

  • 在选择中使用视图:

    从v_最新发布中选择* 按主题\u id分组 按时间戳DESC、位置ASC订购 限制15


  • 因为他想要每个主题的最新帖子。您的查询将针对每个主题随机发布帖子。谢谢,但我似乎不起作用。Phalcons PHQL语言解析器现在搜索名为v_latest_posts的模型。但是找到了一个解决方案,请看这里:使用子查询不会有那么好的效果。退房,我去看看。非常感谢。
    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)
    
    $sql = <<< QUERY
        *query*
    QUERY;
    
    $query = $this->modelsManager->createQuery($sql);
    $result = $query->execute();