php - 创建 3 级子查询 Propel

标签 php mysql symfony propel

大家好,我想问问你们中是否有人知道如何使用 3 级子查询在 propel 中创建 select 语句...最初我有这个查询并且它工作正常但我希望它更像 propel 类型...任何人都可以帮我解决这个问题吗?

这是我的问题

select c.*, count(d.id) as like_count from (
    select a.*, count(b.id) as points_count
    from (
        select * 
        from reviews 
        where user_id ='3') a 
    left join points as b on (a.id = b.type_id) 
    where b.type='review'
    group by a.id 
    order by a.created desc) c left join `like` d on (c.id = d.type_id) group by c.id

这是我到目前为止所拥有的,但仅从 2 级子查询输出查询是不正确的

$review = ReviewsQuery::create()->filterByUserId($user_id);
$points = PointsQuery::create('b')
        ->withColumn("COUNT(b.Id)", 'points_count')
        ->addSelectQuery($review, 'a', true)
        ->toString(); // This is just to check what will be the query output

谁能帮我解决这个问题

最佳答案

我之前没有做过你需要做的事情,并且总是假设当我需要运行像你这样的复杂查询时,我只会让 Propel 运行自定义查询。

这可能不是合适的方法,但我想我会指出它以防万一它不是你见过的东西。在这个页面的一半左右有一个关于如何做的描述:http://propelorm.org/documentation/03-basic-crud.html

关于php - 创建 3 级子查询 Propel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19856621/

相关文章:

php - 在 Twitter Search API 1.1 中排除转推

php - 发出从 POST 读取 JSON

php - n次后如何中止wget

php - 网站如何在不重新加载页面的情况下检查登录凭据?

mysql - 根据不同的标准求和值

php - PhpMyAdmin 能够处理大量数据吗?

php - Symfony 4 和 mongodb :generate:documents

mysql - 如何不在 MySQL 中选择重复的行

forms - 使用 ManyToOne 进行验证

php - Symfony 3 - 通知 : unserialize(): Error at offset 11 of 28 bytes