以下查询代表我正在尝试执行的操作,我需要拉入blog_posts列表并加入用户表。Zend子查询参数
它还在做的是从blog_updates_pictures中随机抽取'picture_filename'。它需要blog_updates作为引用blog_update_id的连接。
我现在想要做的还是计算每个blog_post的blog_updates数量。我认为这是一个子查询,但每个实现都失败了。计数接受参数也是很好的(例如,blog_updates where date =?)。另外,blog_post可能没有更新或图片。
$select = $db->select();
$select->from (array ('b' => 'blog_posts'), array('headline', 'date_created'));
$select->join (array ('u' => 'users'), 'u.user_id = b.user_id', array ('email'));
$select->joinLeft (array ('bu' => 'blog_updates'), 'bu.blog_id = b.blog_id', array());
$select->joinLeft (array ('bup' => 'blog_updates_pictures'), 'bu.blog_update_id = bup.blog_update_id', array ('picture_filename'));
有人可以告诉我方式吗?
感谢
检查此答案以了解如何使用Zend_Db_Select创建子查询http://stackoverflow.com/questions/5604872/nested-select-using-zend-db/5609246#5609246 – satrun77
搭起一个示例架构+数据,我会提出一个解决方案。 –