doc-exports/docs/dws/tool/dws_16_0181.html
Lu, Huayi 27019c2991 DWS TOOL 830.201 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:35:25 +00:00

1.7 KiB

Division Expressions

In MySQL, in a division expression, if the divisor is 0, null is returned. GaussDB(DWS) reports an error. Therefore, the division expression is converted by adding an if condition expression.

Input

select sum(c1) / c2 as result from table_t1;
select sum(c1) / count (c3/c4) as result from table_t1;

Output

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;