IF inputVariable = '0'
THEN
DELETE existingTemptable
WHERE status != 999;
ELSE
IF inputVariable = '1'
THEN
DELETE existingTemptable
WHERE status = 999;
ELSE
DELETE existingTemptable
WHERE status != 999
AND date < utils.dateadd('MONTH', -6, SYSTIMESTAMP);
END IF;
END IF;
此如果逻辑存在于临时表上,则我必须删除该临时表,并使其仅选择查询,因此使用WITH CTE进行了处理,但卡在下面
where子句中的内容
with existingTemptable as
(
//got the temp table here
), myTable as
(
Select * from existingTemptable
**where
status = CASE WHEN inputVariable = '0' THEN 999
WHEN inputVariable != '0' AND inputVariable != '1' THEN 999
ELSE status
END**
)Select * from myTable
在 WHERE 子句中放置什么,以便模仿上面的If逻辑
答案 0 :(得分:0)
如果$optionGroups = OptionGroup::query()
->whereHas('options.attribute' => function ($query) use ($product) {
$query->where('product_id', $product->id);
})
->with(['options.attribute' => function ($query) use ($product) {
$query->where('product_id', $product->id);
}])
->get();
或inputVariable
(或两者)可能是status
,则必须小心。其余的是人们在中学时学习(或应该学习)的逻辑规则的直接应用。
null
注意-即使没有null处理,也不能使用select *
from existingTemptable
where inputVariable = '0' and (status = 999 or status is null)
or
inputVariable = '1' and (status != 999 or status is null)
or
(inputVariable is null or inputVariable not in ('0', '1'))
and (status = 999 or status is null) and date >= [whatever]
表达式编写where
子句;那是因为在一个分支中,您需要“不等于”,并且不能通过简单的case表达式来做到这一点。