我想用laravel 5.2中的子查询编写一个查询,使用where not in子句和下面我已经为我需要写了SQL查询。有人帮我在laravel 5.2模型类中编写这个查询
SELECT
SYSTEM."in_ccws_state"."state_id",
SYSTEM."in_ccws_state"."state"
FROM
SYSTEM."in_ccws_state"
WHERE
SYSTEM."in_ccws_state"."state_id" NOT IN (SELECT DISTINCT
SYSTEM."in_ccws_enable_state"."state_id"
FROM SYSTEM."in_ccws_enable_state"
)
我试过用下面的方法写
$data = DB::table('in_ccws_state')->whereNotIn('state_id', function($q){
$q->select('state_id')->from('in_ccws_enable_state');
})->pluck('in_ccws_state.state', 'in_ccws_state.state_id');
return $data;
因为我需要将数据加载到下拉列表中我使用了“pluck()”而不是“get()”