gpt4 book ai didi

php - joinleft 中的 zend 选择查询

转载 作者:可可西里 更新时间:2023-11-01 07:35:39 25 4
gpt4 key购买 nike

如何在 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'), array('subtopic_id as topic','id as topic_id','grade','chapter_no as chapter','if(file_status=1,1,0) as ppt)','CONCAT("http://eskool.com/learn?t=",subtopic_id) as link'))

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

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

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

关于php - joinleft 中的 zend 选择查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12195839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com