SELECT

 $c->add(AuthorPeer::NAME, "taro");                      // WHERE name = 'taro' 
 $c->add(AuthorPeer::NAME, "taro", Criteria::NOT_EQUAL); // WHERE name <> 'taro'

JOIN

 $c = new Criteria();
 $c->addJoin(ItemPeer::CATETORY_ID, CategoryPeer::ID, Criteria::INNER_JOIN);
 $itemList = ItemPeer::doSelect($c);
 
 // SELECT * FROM item JOIN category ON item.category_id = category.id

GROUP BYしてCOUNT()

 SELECT COUNT(category_id) FROM item GROUP BY category_id
 $c->addSelectColumn('COUNT('.ItemPeer::CATEGORY_ID.')');
 $c->addSelectColumn(ItemPeer::CATEGORY_ID);
 $c->addGroupByColumn(ItemPeer::CATEGORY_ID) ;
 $stmt = ItemPeer::doSelectStmt($c);
 $rows = $stmt->fetchAll(PDO::FETCH_NUM);
 foreach ($rows as $r) {
    $count = $r[0];
    $category_id = $r[1];
 }

http://old.nabble.com/How-to-use-aggregate-functions--td18385850.html

参考

http://propel.phpdb.org/trac/wiki/Ja/Users/Documentation/1.2/UserGuide


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS