我将在我的选择查询中使用IFNULL检查
我想这样执行,当sum为null然后打印0
这是我的整个查询
SELECT
IFNULL(SELECT SUM(TOT_SALES_PRICE) FROM TB_DEALER_SALES_MNG WHERE DEALER_SEQ = 7 AND DATE_FORMAT(SALES_DATE, '%Y%m' )= DATE_FORMAT(NOW(), '%Y%m') ,0)
)AS TOT_SALES_PRICE
语法错误,但我不知道
这是我没有IFNULL的查询,它运作良好 请告诉我
SELECT
(SELECT SUM(TOT_SALES_PRICE) FROM TB_DEALER_SALES_MNG WHERE DEALER_SEQ = 7 AND DATE_FORMAT(SALES_DATE, '%Y%m' )= DATE_FORMAT(NOW(), '%Y%m')
)AS TOT_SALES_PRICE
答案 0 :(得分:1)
SELECT COALESCE(SUM(tot_sales_price),0)) tot_sales_price
FROM tb_deaker_sales_mng
WHERE dealer_seq = 7
AND DATE_FORMAT(sales_date, '%Y%m')=DATE_FORMAT(NOW(), '%Y%m')
或者:
SELECT SUM(COALESCE(tot_sales_price,0)) tot_sales_price
FROM tb_deaker_sales_mng
WHERE dealer_seq = 7
AND DATE_FORMAT(sales_date, '%Y%m')=DATE_FORMAT(NOW(), '%Y%m')