gpt4 book ai didi

mysql - 在 MySQL 中使用 IF 语句

转载 作者:行者123 更新时间:2023-11-29 05:32:42 26 4
gpt4 key购买 nike

我有下面的 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

最佳答案

你需要一个 LEFT JOIN

The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matches in the right table

试试这个

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

关于mysql - 在 MySQL 中使用 IF 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13381367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com