美文网首页
Laravel使用 FIND_IN_SET 匹配字段中的字符串

Laravel使用 FIND_IN_SET 匹配字段中的字符串

作者: 大萝卜2022 | 来源:发表于2023-10-22 14:09 被阅读0次

查询type值 == 2和3的数据

$type = 2,3;
 DB::table('article')->whereRaw('FIND_IN_SET(?,type)',[$type])->get();

Article::whereRaw('FIND_IN_SET(?,type)',[$type])->get();

跟据某个特定顺序去排序查出来的数据:FIND_IN_SET

/返回有顺序的客户id
        $customer_ids = $customer->bespeakTime($uid);
        $res = Customer::with('customer_industry', 'zone1', 'zone2', 'department', 'user.agent', 'tag', 'contact', 'source');
        $res->whereIn('id', $customer_ids)
            ->where('is_call', '>=', 0)
            ->orderByRaw(DB::raw("FIND_IN_SET(id, '" . implode(',', $customer_ids) . "'" . ')'));//按照指定顺序排序

相关文章

网友评论

      本文标题:Laravel使用 FIND_IN_SET 匹配字段中的字符串

      本文链接:https://www.haomeiwen.com/subject/jaoridtx.html