比如要执行如下这样的
sql:
复制内容到剪贴板
代码:
SELECT b.id FROM article_mark a RIGHT JOIN article b ON a.article_id = b.id ORDER BY a.mark DESC,b.CREATED_AT DESC在
symfony中可用这样:
复制内容到剪贴板
代码:
$c=new Criteria();
$c->addAlias('a', 'article_mark'); //!!!if not using alias of table, the generated sql is not correct
$c->addAlias('b', 'article');
$c->addSelectColumn('b.id');
$c->addSelectColumn('a.article_id'); //!!!if one table has no column added, there's no table name after FROM clause;; actually this column is not what I need
$c->addDescendingOrderByColumn('a.mark');
$c->addDescendingOrderByColumn('b.CREATED_AT');
$c->addJoin('a.ARTICLE_ID','b.ID','RIGHT JOIN');
$art_marks=ArticlePeer::doSelectRS($c); //!!! doSelect or doSelectOne can't be used 又比如这样的sql:
复制内容到剪贴板
代码:
select SUM(score) from bury group by article_id having article_id=@ARTICLE_ID在symfony中可以这样来写:
复制内容到剪贴板
代码:
$c=new Criteria();
$c->addSelectColumn('SUM(score) as A'); //actually 'as A' has no use
$c->addSelectColumn(BuryPeer::SCORE); //!! without this, no table name in generated sql; actually this column is not what I need
$c->addGroupByColumn('article_id');
$crit=$c->getNewCriterion(BuryPeer::ARTICLE_ID,$article->getId());
$c->addHaving($crit);
$buries=BuryPeer::doSelectRS($c); //only MySQL recordset can be used