在channel表中查询status,channel_id,channel_name,account_level这些字段,且这些字段的channel_id不在adv_id为$id的表adv_channel_rule中:
$model = new Model();
$id = $req_models["id"];
tp5闭包子查询传参:
$res = $model->table('channel')
->field(['status','channel_id','channel_name','account_level'])
->where('channel_id','NOT IN',function($query) use ($id) {
$query->table('adv_channel_rule')->where("adv_id",$id)->field('channel_id');
})->select();
mysql的原生写法:
$res = 'SELECT adv_id,adv_name,status,account_level FROM `channel` WHERE channel_id NOT IN (SELECT channel_id FROM adv_channel_rule WHERE adv_id='.$id.')';
$result = $model->query($res);
文章转载:https://blog.csdn.net/weixin_36185028/article/details/79499872