更新时间:2024-12-10 GMT+08:00
除法表达式
MySQL中,除法表达式中,当除数为0时,会返回null值。DWS会报错,因此对除法表达式进行转换,增加一个if条件表达式。
输入示例
1 2 |
select sum(c1) / c2 as result from table_t1; select sum(c1) / count (c3/c4) as result from table_t1; |
输出示例
1 2 |
SELECT (if (c2 = 0, null, sum(c1) / c2)) AS "result" FROM table_t1; SELECT (if (count(if (c4 = 0, null, c3 / c4)) = 0, null, sum(c1) / count(if (c4 = 0, null, c3 / c4)))) AS "result" FROM table_t1; |
父主题: 数据操作语句(DML)