这是我的代码
SELECT
IF(or_opp.has_something = 1, metric.a, NULL) as a,
IF(or_opp.has_something = 1, metric.b, NULL) as b,
IF(or_opp.has_something = 1, metric.c, NULL) as c,
IF(or_opp.has_something = 1, metric.d, NULL) as d,
有没有办法写这个,所以我只需要检查or_opp.has_something
一次?
编辑:(出于性能原因)
答案 0 :(得分:0)
也许只是做
SELECT
or_opp.has_something as test,
metric.a as a,
metric.b as b,
metric.c as c,
metric.d as d,
然后在你的脚本语言(我想是PHP)中,在获取行时:
if ($row['test'] != 1)
{
// consider that a, b, c, d are NULL
}
答案 1 :(得分:0)
我有没有理解这个问题,或者你不能把它放在WHERE子句中并在你的SELECT中打印a,b,c,d?
也许发布整个查询。