我正在运行此查询。工作正常但是如果找到NULL
结果,那么它会在我的应用程序中创建异常错误。如何避免NULL
参考
SELECT SUM(pointsEarned) as earned, SUM(pointsRedeemed) as redeemed
FROM `salesData`
WHERE dealerID = @dealerID and status = 'active'
答案 0 :(得分:1)
在COALESCE
周围使用SUM
。
SELECT COALESCE(SUM(pointsEarned),0) earned, COALESCE(SUM(pointsRedeemed),0) redeemed
FROM salesData
WHERE dealerID = @dealerID
AND status = 'active'