【问题标题】:Get non zero values including null获取非零值,包括 null
【发布时间】:2017-12-19 17:24:32
【问题描述】:

我有一个表,其列的值为 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 + 雄辩。如果您提供雄辩的代码,那就太好了。

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

【问题讨论】:

  • 这是 SQL 还是 HTML 表?
  • 只是表中表示的sql数据,供参考。
  • 为什么不只做一个 ASCII 表?

标签: mysql laravel eloquent


【解决方案1】:

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

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

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2020-01-05
    • 1970-01-01
    相关资源
    最近更新 更多