gpt4 book ai didi

mysql - 当 Where 子句中的术语不在数据库中时,如何从 MySQL 数据库返回 0?

转载 作者:可可西里 更新时间:2023-11-01 07:06:45 25 4
gpt4 key购买 nike

如果 WHERE 子句中的邻域不存在,我如何让我的 mysql 数据库返回 0?所以在下面的例子中,Old Town 不在数据库中。我希望数据库返回 0 个事件而不是空结果。

SELECT incidents, 
neighborhoods
FROM `myTable`
WHERE neighborhoods ='Old Town'

我也试过

SELECT IFNULL(incidents,0), 
IFNULL(neighborhoods,0)
FROM `myTable`
WHERE neighborhoods ='Old Town'

如有任何建议,我们将不胜感激。

最佳答案

SELECT COALESCE(SUM(incidents), 0), 'Old Town'
FROM `myTable`
WHERE neighborhoods = 'Old Town'

关于mysql - 当 Where 子句中的术语不在数据库中时,如何从 MySQL 数据库返回 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2394307/

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