gpt4 book ai didi

mysql - 如何在我的 sql 表中获取数据时显示 0 而不是 NULL

转载 作者:行者123 更新时间:2023-11-29 03:56:55 24 4
gpt4 key购买 nike

我正在从 mysql 表中获取数据,它工作正常,但它在两个字段中为 Status 显示 NULL。我想要显示 0 而不是 NULL

这是我的查询:

SELECT ml.GroupID, ml.GroupTitle, ml.GroupDescription, ml.GroupCreatedDateTime, ml.GroupOwnerUserID, ml.ApprovalNeeded, ml.GroupStatus, ml.OrganizationCode, cat.Status
FROM GroupsMaster AS ml
LEFT JOIN UserGroupsMapping cat ON cat.GroupID = ml.GroupID
WHERE ml.OrganizationCode = ?

最佳答案

使用COALESCE运算符(operator)

   COALESCE(cat.Status, 0)


SELECT
ml.GroupID,
ml.GroupTitle,
ml.GroupDescription,
ml.GroupCreatedDateTime,
ml.GroupOwnerUserID,
ml.ApprovalNeeded,
ml.GroupStatus,
ml.OrganizationCode,
COALESCE(cat.Status, 0) as Status
FROM GroupsMaster AS ml
LEFT JOIN UserGroupsMapping cat ON cat.GroupID = ml.GroupID
WHERE ml.OrganizationCode = 'ibm'

关于mysql - 如何在我的 sql 表中获取数据时显示 0 而不是 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17694672/

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