有没有办法在两个表上执行 LEFT OUTER JOIN 时插入零而不是 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`
如我错了请纠正我
如果字段为 NULL,则使用ISNULL(field, 0)
它将插入零
CASE WHEN a.fieldname IS NULL
THEN 0
ELSE a.fieldname
END AS fieldname
就像是:-
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