$query->whereNotExists(function ($query) use ($where){
$query->select(DB::raw(1))
->from('saas_commission_config_staff as cs')
->whereRaw('cs.type = '.$where['rent_sell'])
->whereRaw('cs.staff_id = saas_staff.id');
});
mysql中的 IN 与 EXIST的区别 :
in语句是把外表和内表作hash 连接,
exists语句是对外表作loop循环,每次loop循环再对内表进行查询。
EXISTS
带有EXISTS的子查询不返回任何数据,只产生逻辑真值“true”或者逻辑假值“false”。
NOT EXISTS
与EXISTS相对的是NOT EXISTS。使用NOT EXISTS后,若对应查询结果为空,则外层的WHERE子语句返回值为真值,否则返回假值。