SQL BETWEEN Two Columns in Laravel/Lumen

后端 未结 1 1902
花落未央
花落未央 2021-02-07 17:40

Below is an excerpt from the Laravel documentation:

The whereBetween method verifies that a column\'s value is between two values:

$users = DB::

1条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 18:01

    There is no alternative to the whereBetween method that applies to two columns. You can however do this in one of two ways:

    1. Use whereRaw with bindings, where you use the raw condition and a binding for the variable:

    whereRaw('? between saturday_ot and saturday_ct', [$t])
    

    2. Use a where with two conditions that use the two column values as boundaries for the $t variable value:

    where(function ($query) use ($t) {
        $query->where('saturday_ot', '<=', $t);
        $query->where('saturday_ct', '>=', $t);
    })
    

    0 讨论(0)
提交回复
热议问题