gpt4 book ai didi

php - 如果在 mysql 中值为 Null,则使用 CONCAT 时出现问题

转载 作者:行者123 更新时间:2023-11-29 02:07:26 35 4
gpt4 key购买 nike

我使用 CONCAT 获取标签和主题,但如果故事没有标签或主题,则结果为空

 WHERE 

CONCAT( ' ', table_stories.tags, ' ' )
LIKE CONCAT( '%', table_tags.tid, '%' )

AND

CONCAT( ' ', table_stories.associated, ' ' )
LIKE CONCAT( '%', table_topics.topicid, '%' )

如你所见,一切都很好,除非我们有没有标签或关联的故事

我用过

  table_stories.tags IS NULL OR

但问题仍然存在,无法获取没有标签或关联的故事

我该如何解决这个问题

最佳答案

我没有方便测试的 mysql,但 COALESCE() 可能是您正在寻找的函数。

这将返回第一个非空参数(参见 Documentation)

所以

CONCAT(' ' , COALESCE(table_stories.associated, ' '), ' ')

应该做的工作

关于php - 如果在 mysql 中值为 Null,则使用 CONCAT 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3474477/

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