Mysql交换机案例返回不正确的结果
考虑my mysql表中的以下行:Mysql交换机案例返回不正确的结果,mysql,Mysql,考虑my mysql表中的以下行: id Url Urls 6433 ["https://do.foo/", "https://do.foo/2"] 我需要用url列中的第一个url填充url,无论它是空的。所以我运行了这个查询: select coalesce(url, '') = '' as `is_true` , convert(JSON_EXTRACT(urls, '$[0]'), CHAR) as `extracted`, case url when co
id Url Urls
6433 ["https://do.foo/", "https://do.foo/2"]
我需要用url
列中的第一个url
填充url,无论它是空的。所以我运行了这个查询:
select coalesce(url, '') = '' as `is_true` ,
convert(JSON_EXTRACT(urls, '$[0]'), CHAR) as `extracted`,
case url
when coalesce(url, '') = '' then convert(JSON_EXTRACT(urls, '$[0]'), CHAR)
else '3'
end as `valid_url`
from table_name where id = 6433 ;
结果是:
is_true extracted valid_url
1 "https://do.foo/" 3
是否有任何原因导致提取的url不显示在有效url列中 您的
案例
表达式不正确。当您在表达式中编写CASE列时,会将列
中的值与表达式进行比较,因此在您的示例中,您将url
(即NULL
)与”
(失败)进行比较。将大小写
表达式更改为表达式
窗体时的大小写,或将url
更改为合并(url),
并将表达式更改为'
。例如:
select coalesce(url, '') = '' as `is_true` ,
convert(JSON_EXTRACT(urls, '$[0]'), CHAR) as `extracted`,
case
when coalesce(url, '') = '' then convert(JSON_EXTRACT(urls, '$[0]'), CHAR)
else '3'
end as `valid_url`
from table_name where id = 6433
或
在这两种情况下,输出为:
is_true extracted valid_url
1 "https://do.foo/" "https://do.foo/"
is_true extracted valid_url
1 "https://do.foo/" "https://do.foo/"