获取非零值,包括null

时间:2017-12-19 17:24:32

标签: mysql laravel eloquent

我有一个表的列,其值为0,null和1.我需要记录具有非0值,包括null和1.我需要使用eloquent进行查询。

我的表格如下:

id | user_id | medical | gsg  |interview_result | flight | created_at
----------------------------------------------------------------------
 1 |   1     | null    | null |      1          | null   | anydate
 2 |   2     |   0     | null |      1          | null   | anydate
 3 |   3     |   1     |   1  |      1          |   1    | anydate
 4 |   8     |   1     |   1  |      1          |   0    | anydate

请回答这个问题。我想要非0值,包括null。 Mysql + Eloquent。如果您提供雄辩的代码,那就太好了。

注意:gsg,medical,interview_result应为非0,包括null。不需要使用其他栏目。

1 个答案:

答案 0 :(得分:0)

您必须使用where clause来匹配不包含0的行,这是一个示例:

DB::table('table')
    ->where('gsg', '<>', 0)
    ->where('medical', '<>', 0)
    ->where('interview_result', '<>', 0)
    ->get();

希望这有帮助

相关问题