Laravel/SQL:其中列等于NOT和NULL [英] Laravel/SQL: where column Equals NOT and NULL

查看:273
本文介绍了Laravel/SQL:其中列等于NOT和NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LARAVEL 5.4(但可能是一个更通用的SQL问题)

LARAVEL 5.4 (but probably it's a more general SQL question)

你好!我有一个结构表:

Hello! I have a table with a structure:

假设它是我的模型"Table".

Suppose it's my model 'Table'.

我想要一个查询:

使用(接收)变量:

$ id 数组['id','string',整数]

$id of array ['id', 'string', integer]

其中字符串为'<'或'>'

$ status_not_bad = bool;

(如果为true,则包括状态"!==不良"和状态"为NULL的所有行);

例如,给我们:

$id = [['id', '>', 0]];

$status_not_bad = true;

Table::thisquery() ... ->get();

获取状态不错且id> 0的行"将返回第1行和第3行.

但如果我们给出:

$id = [['id', '<', 3]];

$status_not_bad = true;

Table::thisquery() ... ->get();

获取状态不差且id <3的行"返回第1行

(应该是使用这些变量返回结果的同一查询).

(it should be same query which return those results using those variables).

推荐答案

由于行id = 3,您需要在where语句中使用<=将该行包含在结果集中

Since row id = 3 you need <= in your where statement to have that row included in the result set

$id = ['id', '<=', 3];

这篇关于Laravel/SQL:其中列等于NOT和NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆