我从mysql表中获取数据它工作正常,但它在两个字段中显示NULL
Status
。我希望代替NULL
显示0
。
这是我的问题:
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 = ?
答案 0 :(得分:8)
使用COALESCE运算符
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'
答案 1 :(得分:0)
您可以尝试ifnull()功能。 如下:
选择 ifnull (cat.status,0)作为状态
FROM GroupsMaster AS ml
LEFT JOIN UserGroupsMapping cat ON cat.GroupID = ml.GroupID
WHERE ml.OrganizationCode ='$ organizationCode'“);
答案 2 :(得分: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
and ml.OrganizationCode = 'ibm'