标签:lse col sel sele for span thinkphp 理论 table
public function showname() { $date = date(‘Y-m-d‘); $ddd=Db::table(‘xinguan‘) ->where(‘date‘,‘=‘, $date) ->field(‘name‘) ->select(false); $data= Db::table(‘name‘) ->field(‘user_name‘) ->whereNotIn(‘user_name‘,$ddd) ->select(false); //不查询,直接输出SQL return $data; }
理论输出SQL语句
SELECT `user_name` FROM `name` WHERE `user_name` NOT IN (SELECT `name` FROM `xinguan` WHERE `date` = ‘2020-02-15‘)
实际输出的SQL语句是
SELECT `user_name` FROM `name` WHERE `user_name` NOT IN (‘SELECT `name` FROM `xinguan` WHERE `date` = \‘2020-02-15\‘‘)
明显的上面的语句有问题.
没办法只能先把第一查询先运行并遍历生成一个数组赋值给第二查询
public function showname() { $date = date(‘Y-m-d‘); $ddd=Db::table(‘xinguan‘) ->where(‘date‘,‘=‘, $date) ->field(‘name‘) ->select(); foreach ($ddd as $key=>$value){ $arr[$key]=$value[‘name‘]; } $data= Db::table(‘name‘) ->field(‘user_name‘) ->whereNotIn(‘user_name‘,$arr) ->select(); return $data; }
标签:lse col sel sele for span thinkphp 理论 table
原文地址:https://www.cnblogs.com/binxl/p/12315429.html