thinkphp6条件where指定字段为空或不为空查询

文章描述:

mysql查询指定字段值不为空

 

 

 

指定字段为空条件查询

写法一

$where[] = ['title','=',null];
Db::name('service')->where($where)->select();

SELECT * FROM `lbs_service` WHERE `title` IS NULL

 

写法二

Db::name('service')->where('title',null)->select();

SELECT * FROM `lbs_service` WHERE `title` IS NULL

 

指定字段不为空

写法一

Db::name('area')->where('title','=', 'not null')->select();

SELECT * FROM `lbs_service` WHERE `title` = ‘not null’

 

写法二

Db::name('area')->whereNotNull('title')->select();

SELECT * FROM `lbs_service` WHERE `title` IS NOT NULL

 

 

$filter['name'] = array('NEQ',' ');
$service_type_lists = $serviceModel->where($filter)->select()->toArray();

SELECT * FROM `lbs_service` WHERE `name` IN (‘NEQ’,’ ‘)

 

$serviceModel->field('type,name')->where('name','not null')->select()->toArray();

SELECT `type`,`name` FROM `lbs_service` WHERE `name` IS NOT NULL

 

当name不为Null时,但name=”时,查询方式如下

SELECT * FROM `service` WHERE `name` IS NOT NULL AND NOT name= ''

 

$list = $model->field('code,name,region')->where('region','not null')->where("NOT region='' ")->select()->toArray();

SELECT `code`,`name`,`region` FROM `lbs_city` WHERE `region` IS NOT NULL AND ( NOT region=” )

发布时间:2023/11/13

发表评论