gpt4 book ai didi

mysql - 子查询返回 Ifnull...NULL

转载 作者:行者123 更新时间:2023-11-29 00:23:18 24 4
gpt4 key购买 nike

当我在 NULL 值上期望 0 时,为什么这个子查询返回 NULL 的任何想法:

SELECT
(SELECT ifnull(visit.timestamp, 0) AS ifnull_1
FROM keyword
WHERE visit.keyword_id = keyword.id
ORDER BY visit.timestamp DESC LIMIT 1) AS keyword_last_visit
FROM keyword
LEFT OUTER JOIN visit ON visit.keyword_id = keyword.id

keyword_last_visit 总是返回 NULL

最佳答案

CASE 试试这个

SELECT 
(SELECT (CASE WHEN visit.timestamp IS NULL THEN 0 ELSE visit.timestamp END) AS ifnull_1
FROM keyword
WHERE visit.keyword_id = keyword.id
ORDER BY visit.timestamp DESC LIMIT 1) AS keyword_last_visit
FROM keyword
LEFT OUTER JOIN visit ON visit.keyword_id = keyword.id

关于mysql - 子查询返回 Ifnull...NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20250472/

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