在mysql中执行左外连接时插入零而不是空

hgncfbus  于 2021-06-20  发布在  Mysql
关注(0)|答案(3)|浏览(288)

在两个表上执行左外联接时,有没有方法插入一个零而不是null?
假设我有这样一个查询:

SELECT * FROM
(SELECT uID from Class) T1
LEFT OUTER JOIN
(SELECT pID from University) T2
ON T1.uID = T2.pID
CASE WHEN T1.uID IS NULL
    THEN 0
ELSE T1.uID
END AS uID`

如果我错了就纠正我

gwbalxhn

gwbalxhn1#

CASE WHEN a.fieldname IS NULL 
       THEN 0
       ELSE a.fieldname
END AS fieldname
xienkqul

xienkqul2#

使用 ISNULL(field, 0) 如果字段为空,则将插入零

wbrvyc0a

wbrvyc0a3#

什么like:-

SELECT * FROM
(SELECT ifnull(uID,0) as uID from Class) T1
   LEFT OUTER JOIN
 (SELECT ifnull(pID,0) as pID from University) T2
   ON T1.uID = T2.pID

相关问题