gpt4 book ai didi

mysql - Zend DB Select : ORDER BY FIELD ('id' , some_array) - 怎么样?

转载 作者:IT老高 更新时间:2023-10-29 00:06:07 27 4
gpt4 key购买 nike

您将如何在 Zend 框架中编写以下查询?

SELECT * FROM table_name ORDER BY FIELD(field_name, 'Small','Medium','Large');

我只需要“Order by”部分 :)

谢谢!

最佳答案

这个呢:

      $db = Zend_Db_Table::getDefaultAdapter();

$select = $db->select();

$select->from('table_name')
->order(new Zend_Db_Expr("FIELD(field_name, 'Small','Medium','Large')"));


var_dump($select->assemble());

结果:

string 'SELECT `table_name`.* FROM `table_name` ORDER BY FIELD(field_name, 'Small','Medium','Large')' (length=92)

关于mysql - Zend DB Select : ORDER BY FIELD ('id' , some_array) - 怎么样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6612037/

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