我有麻烦写在laravel雄辩的ORM查询。
我的问题是
SELECT book_name,dt_of_pub,pub_lang,no_page,book_price
FROM book_mast
WHERE book_price NOT IN (100,200);
现在我想把这个问题转换成laravel雄辩。
我有麻烦写在laravel雄辩的ORM查询。
我的问题是
SELECT book_name,dt_of_pub,pub_lang,no_page,book_price
FROM book_mast
WHERE book_price NOT IN (100,200);
现在我想把这个问题转换成laravel雄辩。
当前回答
可以通过以下方式使用WhereNotIn:
$category=DB::table('category')
->whereNotIn('category_id',[14 ,15])
->get();`enter code here`
其他回答
查询构建器:
DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();
口才:
SomeModel::select(..)->whereNotIn('book_price', [100,200])->get();
您可以使用此示例动态调用Where NOT IN
$user = User::where('company_id', '=', 1)->select('id)->get()->toArray(); $otherCompany = User::whereNotIn('id', $user)->get();
查询构建器:
DB::table('book_mast')
->select('book_name','dt_of_pub','pub_lang','no_page','book_price')
->whereNotIn('book_price', [100,200])->get();
口才:
BookMast::select('book_name','dt_of_pub','pub_lang','no_page','book_price')
->whereNotIn('book_price', [100,200])->get();
可以通过以下方式使用WhereNotIn:
$category=DB::table('category')
->whereNotIn('category_id',[14 ,15])
->get();`enter code here`
在我添加方法->toArray()到结果之前,我有一个子查询问题,我希望它能帮助更多,因为我有一个很好的时间寻找解决方案。
例子
DB::table('user')
->select('id','name')
->whereNotIn('id', DB::table('curses')->select('id_user')->where('id_user', '=', $id)->get()->toArray())
->get();