CleverCode最近在导出报表的时候,在整数做减法的时候,发现整数减去null得到是null。这是一个细节问题,希望大家以后注意。
select id, total, used, (total - used) as have from test_table
select id, ifnull(total,0) as total, ifnull(used,0) as used, (ifnull(total,0) - ifnull(used,0)) as have from test_table