当前位置 : 主页 > 数据库 > mysql >

详谈mysql order by in 的字符顺序(推荐)

来源:互联网 收集:自由互联 发布时间:2021-04-30
//MySQL 语句SELECT * FROM `MyTable`WHERE `id` IN (11,1,111) ORDER BY FIELD(`id`, 11,1,111); laravel 框架 $ids = array(1,17,2);$ids_ordered = implode(',', $itemIds);$items = static::whereIn('id', $ids)-orderByRaw(DB::raw("FIELD(id, $ids_
//MySQL 语句SELECT * FROM `MyTable`WHERE `id` IN (11,1,111) ORDER BY FIELD(`id`, 11,1,111); 

laravel 框架

$ids = array(1,17,2);

$ids_ordered = implode(',', $itemIds);

$items = static::whereIn('id', $ids)->orderByRaw(DB::raw("FIELD(id, $ids_ordered)"))->get();

以上这篇详谈mysql order by in 的字符顺序(推荐)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

网友评论