当一个为null时添加子查询

时间:2016-10-02 20:05:06

标签: mysql sum subquery

SELECT (select sum(furniture.furniture_sales)
            from furniture
            where cp.userid = furniture.userid) + 
        (select sum(electronics.electronic_sales)
            from electronics
            where cp.userid = electronics.userid) as total  
FROM customer_profile cp

基本上,如果家具或电子产品中不存在用户标识,则“保持”将返回NULL。我能做什么,以便'total'将返回一个值而不是NULL?

0 个答案:

没有答案