SELECT a.org_name,
IF(a.mm_id IS NULL,'yes','no') AS failed,
IF(a.mm_id IS NULL AND a.active = 'Y', 'yes', 'no') AS active,
IF(a.mm_id IS NULL AND a.xaction = 'Y','yes','no') AS xaction
FROM campaign a
``` `IF` (是比较函数)和 `WHEN THEN` 你的问题有解决办法吗
SELECT a.org_name,
CASE WHEN a.mm_id IS NULL THEN 'yes' ELSE 'no' END AS failed,
CASE WHEN a.mm_id IS NULL AND a.active = 'Y' THEN 'yes' ELSE 'no' END AS active,
CASE WHEN a.mm_id IS NULL AND a.xaction = 'Y' THEN 'yes' ELSE 'no' END AS xaction
FROM campaign a
5条答案
按热度按时间i7uq4tfw1#
+--------+--------+---------+ | Pepsi | yes | no | yes | | Xerox | no | no | yes | +
gk7wooem2#
91zkwejq3#
+--------+--------+---------+`
euoag5mw4#
+--------+--------+---------+ | org_name | failed | active | xaction | +
brtdzjyr5#
为您在问题中指定的确切条件生成结果的查询如下所示:
你只需替换每个
CASE
按要求表达。