dtgj8529
dtgj8529
2010-11-10 11:03

如何在推进中使用子查询获取行计数(来自另一个表)?

已采纳

I want to do something like this:

SELECT a.*, (SELECT COUNT(*) FROM b where b.col1 = a.col2) as count FROM a

is it possible using propel criteria or not?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dtvdz911959 dtvdz911959 11年前
    $c = new Criteria();
    $c->addSelectColumn(aPeer::TABLE_NAME.'.*');
    $c->addAsColumn('count', '(SELECT COUNT(*) FROM b WHERE b.col1 = a.col2)');
    aPeer::doSelect($c);
    
    点赞 评论 复制链接分享