获取非零值,包括null

问题描述 投票:-1回答:1

我有一个表的列具有值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。不需要使用其他列。

mysql laravel eloquent
1个回答
0
投票

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

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

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.