php – zend select joinleft中的查询

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – zend select joinleft中的查询脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
何在Zend模型中的JOIN LEFT中编写SELECT查询
例如,如何将以下 mysql查询转换为zend模型查询

LEFT JOIN 
    (SELECT count(*) as game_count,topic_id,time as g_time From games_list WHERE tyPE < 3 group by topic_id) t3
    ON chapter_list.id=t3.topic_id

我想用以下的zend查询添加转换后的查询,我需要从上面的查询中得到game_count,结果如下.

$query = $this->select()

    ->setIntegrITyCheck(false)

    ->from(array('a' => 'chapter_list'),array('suBTopic_id as topic','id as topic_id','grade','chapter_no as chapter','if(file_status=1,1,0) as ppt)','CONCAT("http://mysite.COM?t=",subtopic_id) as link'))

    ->joinLeft(array('b' => 'subject_list'),'a.subject = b.subject_id',array());

    return $this->fetchAll($query)->toArray();

解决方法

终于我明白了,

$subquery1= $this->select()

    ->setIntegrityCheck(false)

    ->from('games_list',array('count(*) as game_count','topic_id','time as g_time'))

    ->where('type<?',3)

    ->group('topic_id');

     //main query
     $query = $this->select()

    ->setIntegrityCheck(false)

    ->from(array('a' => 'chapter_list'),'CONCAT("http://eskool.com/learn?t=",array())

    ->joinLeft(array('c' => $subquery1),'a.id = c.topic_id',array('IFNULL(game_count,0)','g_time'))

    return $this->fetchAll($query)->toArray();

脚本宝典总结

以上是脚本宝典为你收集整理的php – zend select joinleft中的查询全部内容,希望文章能够帮你解决php – zend select joinleft中的查询所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。