gpt4 book ai didi

mysql - 分组前的 Zend 框架顺序

转载 作者:行者123 更新时间:2023-11-29 07:00:36 26 4
gpt4 key购买 nike

有没有人举例说明如何在 zend 分页器适配器中使用 leftjoin 在组前排序?

new Zend_Paginator_Adapter_DbSelect($this->db->select()
->from(array( 'a' => $this->prefix.'contest' ), array('id'))
->joinLeft(array( 'b' => $this->prefix.'logo_to_contest'),'a.id=b.contest_id', array('img'))
->group('a.id')
->order('a.end','a.date_start DESC','b.id RAND()')
)

最佳答案

来自 mysql 手册

In general, clauses used must be given in exactly the order shown in the syntax description. For example, a HAVING clause must come after any GROUP BY clause and before any ORDER BY clause. The exception is that the INTO clause can appear either as shown in the syntax description or immediately following the select_expr list.

并且在 syntax description group 在 order 之前出现,所以它与 zend 无关mysql 要求先组后序。

然而,为了解决这个问题并在排序后分组,您可以使用带有顺序的子查询进行选择,然后在新的选择上分组,例如:

$subselect = $db->select()
->from(array( 'a' => $this->prefix.'contest' ), array('id'))
->joinLeft(array( 'b' => $this->prefix.'logo_to_contest'),'a.id=b.contest_id', array())
->order('a.end','a.date_start DESC','b.id RAND()');

$select = $db->select()->from(a(array( 'a' => $this->prefix.'contest' ), array('id'))
->joinLeft(array( 'b' => $this->prefix.'logo_to_contest'),'a.id=b.contest_id', array('img'))
->where("a.id in ($subselect)")
->group('a.id');

关于mysql - 分组前的 Zend 框架顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10363886/

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