如何使用 Zend_Db_Select 对象编写此查询?
SELECT
`v1`.`id`,
`v1`.`title`,
`v1`.`duration`,
`v1`.`img`
FROM
`videos` AS `v1`
WHERE
v1.id IN (
SELECT id_video FROM videos_categories WHERE id_video NOT IN(
select id_video from videos_categories where id_category=34
UNION
select id_video from videos_categories where id_category=20
)
)
我尝试了类似的方法,但没有任何效果,我有一个错误页面。我使用数据映射器
$objQuery = $this->getDbTable()->select()
->from(array('v'=>'videos'),array('v.id','v.title','v.duration','v.img'))
$tableVC1 = new Application_Model_DbTable_VideosCategories();
$tableVC2 = new Application_Model_DbTable_VideosCategories();
$tableVC3 = new Application_Model_DbTable_VideosCategories();
$tableVC4 = new Application_Model_DbTable_VideosCategories();
// select id_video from videos_categories where id_category=20
$tableVC4->select()->from(array("vc"=>"videos_categories"),array("id_video"))
->where("vc.id_category=20");
// select id_video from videos_categories where id_category=34
$tableVC3->select()->from("videos_categories","id_video")
->where("id_category=34");
// union between previous queries
$tableVC2->select()->union(array($tableVC4,$tableVC3));
$tableVC1->select()->from("videos_categories","id_video")
->where("id_video NOT IN ?",$tableVC2);
$objQuery->where("v.id IN ?",$tableVC1);
谢谢帮助我。