Sql 其中,laravel中的列为null
我需要比较表中的两列,但如果其中一列为null,则查询返回空 身份证件 名称 原价 销售价格 1. 洗发水 2.30 无效的Sql 其中,laravel中的列为null,sql,laravel,laravel-8,laravel-7,laravel-6,Sql,Laravel,Laravel 8,Laravel 7,Laravel 6,我需要比较表中的两列,但如果其中一列为null,则查询返回空 身份证件 名称 原价 销售价格 1. 洗发水 2.30 无效的 只需在两列上添加whereNotNull,如果其中一列为null,则查询条件将不匹配,并且不返回任何记录 $this->products = Product::whereColumn('original_price', '!=', 'sale_price') ->whereNotNull("original_price&qu
只需在两列上添加whereNotNull,如果其中一列为null,则查询条件将不匹配,并且不返回任何记录
$this->products = Product::whereColumn('original_price', '!=', 'sale_price')
->whereNotNull("original_price")
->whereNotNull("sale_price")
->get()
如果希望此类查询同时返回Null值,则应使用orWhereNull
$this->products = Product::whereColumn('original_price', '!=', 'sale_price')
->orWhereNull("original_price")
->orWhereNull("sale_price")
->get()
顺便说一句:如果两者都为空,则字段相等,但查询不会为空,但我希望查询返回此产品。