在数据库中查询以逗号分割的数据

return self::find()
            ->where(["is_del" => 0, "status" => 1])
            ->andWhere('CONCAT(",", `user_category_id`, ",") REGEXP ",('. implode('|', $categoryIds) .'),"')
            ->orderBy("weight DESC")
            ->one();

$categoryIds是一个数组,要查询表中以逗号分割的数据是否命中该数组中的任何一个元素
posted @ 2022-01-26 16:56  你的男孩  阅读(337)  评论(0编辑  收藏  举报