gpt4 book ai didi

mysql - 如果 mysql 查询为空,则复制一个值

转载 作者:行者123 更新时间:2023-11-29 21:40:04 26 4
gpt4 key购买 nike

我的查询遇到问题,有时会返回空字段。我尝试过使用 CASE 和 COALESCE,但我可能错误地构造了查询。

我需要在结果中做的是,如果 b.user_id 返回空,则将值从 a.useracctid 复制到 b.user_id 中。我希望这是有道理的???

这是我的查询,无论我尝试过什么,它对我来说都是错误的。

感谢您提供的任何想法或提示

SELECT b.user_id,a.responsetime,a.latitude,a.longitude,
a.status,a.updatetime,c.address
FROM callouts_response a
LEFT JOIN ldap_user_accounts b on a.useracctid = b.id
LEFT JOIN callouts c on a.calloutid = c.id
WHERE calloutid = :cid

最佳答案

不确定您如何使用COALESCE(),但您可以这样做

SELECT COALESCE(b.user_id,a.useracctid) as somecol,
a.responsetime,
a.latitude,
a.longitude,
a.status,
a.updatetime,
c.address
FROM callouts_response a
LEFT JOIN ldap_user_accounts b on a.useracctid = b.id
LEFT JOIN callouts c on a.calloutid = c.id
WHERE a.calloutid = :cid

关于mysql - 如果 mysql 查询为空,则复制一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34604220/

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