gpt4 book ai didi

mysql - IFNULL() 可以使用 MySQL 返回列值为 int 的字符串吗?

转载 作者:行者123 更新时间:2023-11-29 06:12:04 24 4
gpt4 key购买 nike

我的查询

select cname, count(screening_occapancy.idclient) as 'Count'
from client, screening_occapancy
where client.client_no = screening_occapancy.idclient
group by cname

返回以下内容:

Name        Count
Name1 2
Name2 3
Name3 6

等等,现在我希望如果值为 null 或 0,则“Count”中的值“未找到”,这可能吗?我的结果中需要类似的东西:

    Name        Count
Name1 2
Name2 3
Name3 "Not found"

最佳答案

    Select cname , 
case when Count is null or count =0 then 'Not found'
else Count end as count
from
(select cname,
count(screening_occapancy.idclient) as 'Count'
from client left join screening_occapancy
on
client.client_no = screening_occapancy.idclient group by cname) t

在查询上方写一个包装器查询以检查计数列

关于mysql - IFNULL() 可以使用 MySQL 返回列值为 int 的字符串吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37765920/

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