我如何使用 if in SQL 查询
How can I use if in SQL query
SQL 也可以 运行 像下面这样的查询吗?因此,首先我们将查看一个值,相应地我们将查看其他值。
SELECT * FROM IF WHERE `status` != 'true' ELSE WHERE `status_2` == 'false'
那么我们如何在 laravel october CMS 中进行调整,如下所示。
$query->whereHas('avaibleDates', function($q) {
if ( $q->where('start_date', '<=', 2) ) {
$q->where('status_id', '!=', 2);
}
});
所以我们要运行一种情况查询,另一种情况查询。
根据你的描述,我不太明白你想做什么))。我想你需要这样的演员表:
$query->whereHas('avaibleDates', function($q) {
$q->where(function ($q) {
$q->where('start_date', '<=', 2)->where('status_id', '!=', 2);
});
// The following conditions
...
$q->orWhere(function ($q) {
$q->where('start_date', '>', 55)->where('status_id', '!=', 7);
});
...
});
SQL 也可以 运行 像下面这样的查询吗?因此,首先我们将查看一个值,相应地我们将查看其他值。
SELECT * FROM IF WHERE `status` != 'true' ELSE WHERE `status_2` == 'false'
那么我们如何在 laravel october CMS 中进行调整,如下所示。
$query->whereHas('avaibleDates', function($q) {
if ( $q->where('start_date', '<=', 2) ) {
$q->where('status_id', '!=', 2);
}
});
所以我们要运行一种情况查询,另一种情况查询。
根据你的描述,我不太明白你想做什么))。我想你需要这样的演员表:
$query->whereHas('avaibleDates', function($q) {
$q->where(function ($q) {
$q->where('start_date', '<=', 2)->where('status_id', '!=', 2);
});
// The following conditions
...
$q->orWhere(function ($q) {
$q->where('start_date', '>', 55)->where('status_id', '!=', 7);
});
...
});