1

大家好,我想问一下你们中是否有人知道如何使用 3 级子查询在推进器中创建选择语句......最初我有这个查询,它工作正常,但我希望它更像推进器类型......谁能帮我这个?

这是我的查询

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

谁能帮我解决这个问题

4

2 回答 2

1

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

这可能不是适当的方法,但我想我会指出它以防万一它不是你看到的东西。在这个页面上大约一半的地方有关于如何做到这一点的描述:http: //propelorm.org/documentation/03-basic-crud.html

于 2013-11-08T12:44:18.730 回答
0

您可以通过以下方式对子查询进行动画处理:

__1级

$c1 = new ReviewsQuery();//First query
$c1->addSelfSelectColumns();//implement all columns
$c1->filterByUserId(3);//the where clause --where user_id ='3'--

__2级

$s1 = new ReviewsQuery();//Second Level 
$s1->addSelectQuery($c1,"a"); // Implements first query
$s1->addAlias("b",PointsTableMap::COL_TYPE_ID); //prepare Join
$s1->addJoin("a.Id",PointsTableMap::alias("b",PointsTableMap::COL_TYPE_ID))//Add the join
$s1->where(PointsTableMap::alias("b",PointsTableMap::COL_TYPE)."=?",'review')//filter by -- where b.type='review' --

(...分组...选择...等...)

__3 级

$c3 = new ReviewsQuery();//The high level Query
$c3->addSelectQuery($s1,"c");//adding a subquery as "c" 
$c3->addJoin... //continue as a normal Query Object

小心命名空间...... Propel2 中存在一些错误

于 2015-12-02T11:18:28.933 回答