SELECT count(1) all_num, IFNULL( sum( CASE WHEN a.pay_status = 1 THEN 1 ELSE 0 END ), 0 ) success_num, IFNULL( sum( CASE WHEN a.pay_status = 2 THEN 1 ELSE 0 END ), 0 ) paying_num, IFNULL( sum( CASE WHEN a.pay_status = 1 THEN a.real_money ELSE 0 END ), 0 ) real_amount FROM order_base a, requisition_order b, requisition_base c WHERE a.id = b.order_id AND b.requisition_id = c.id AND b.relation_status = 1 AND c.id = #{requisitionId}
MySQL IFNULL
函数是MySQL控制流函数之一,它接受两个参数,如果不是NULL
,则返回第一个参数。 否则,IFNULL
函数返回第二个参数。
IFNULL(expression_1,expression_2);
SQL SUM() 语法
SELECT SUM(count) FROM table_name;