1

我有以下 SQL 语句。我想做的是包含一个 IF 语句,以涵盖其中一列返回 0 或空白结果的可能性,没有 0 ID。在这种情况下,我试图涵盖magez_cfv_nations结果可能返回零或空白结果的可能性。

SELECT c.clan_name, n.nation_name, 
    CONCAT(r.rarity_shorthand, " - ", r.rarity_name) AS rarity_text, 
    t.trigger_name, s.skill_name
 FROM `magez_cfv_cards` AS cards
 JOIN `magez_cfv_clans` c ON cards.clan_id = c.clan_id
 JOIN `magez_cfv_nations` n ON cards.nation_id = n.nation_id
 JOIN `magez_cfv_rarity` r ON cards.rarity_id = r.rarity_id
 JOIN `magez_cfv_trigger` t ON cards.trigger_id = t.trigger_id
 JOIN `magez_cfv_skills` s ON cards.skill_id = s.skill_id
4

2 回答 2

2

你需要一个LEFT JOIN

LEFT JOIN 关键字返回左表 (table_name1) 中的所有行,即使右表中没有匹配项

试试这个

SELECT c.clan_name, n.nation_name, 
    CONCAT(r.rarity_shorthand, " - ", r.rarity_name) AS rarity_text, 
    t.trigger_name, s.skill_name
 FROM `magez_cfv_cards` AS cards
 JOIN `magez_cfv_clans` c ON cards.clan_id = c.clan_id
 LEFT JOIN `magez_cfv_nations` n ON cards.nation_id = n.nation_id
 JOIN `magez_cfv_rarity` r ON cards.rarity_id = r.rarity_id
 JOIN `magez_cfv_trigger` t ON cards.trigger_id = t.trigger_id
 JOIN `magez_cfv_skills` s ON cards.skill_id = s.skill_id
于 2012-11-14T15:06:41.500 回答
1

你应该使用的函数是IIF(),它的语法是

IIF([condition],[if true],[if false])
于 2012-11-14T15:07:26.650 回答