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

18 lines
1.7 KiB
HTML

<a name="EN-US_TOPIC_0000001819336237"></a><a name="EN-US_TOPIC_0000001819336237"></a>
<h1 class="topictitle1">Division Expressions</h1>
<div id="body8662426"><p id="EN-US_TOPIC_0000001819336237__en-us_topic_0000001657865278_en-us_topic_0000001442280317_p162131353125718">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.</p>
<p id="EN-US_TOPIC_0000001819336237__en-us_topic_0000001657865278_en-us_topic_0000001442280317_p2021345315571"><strong id="EN-US_TOPIC_0000001819336237__en-us_topic_0000001657865278_en-us_topic_0000001442280317_b95474251051">Input</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001819336237__en-us_topic_0000001657865278_en-us_topic_0000001442280317_screen151011302057">select sum(c1) / c2 as result from table_t1;
select sum(c1) / count (c3/c4) as result from table_t1;</pre>
<p id="EN-US_TOPIC_0000001819336237__en-us_topic_0000001657865278_en-us_topic_0000001442280317_p921318531577"><strong id="EN-US_TOPIC_0000001819336237__en-us_topic_0000001657865278_en-us_topic_0000001442280317_b2100163316513">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001819336237__en-us_topic_0000001657865278_en-us_topic_0000001442280317_screen199374362514">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;</pre>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_16_0178.html">SELECT</a></div>
</div>
</div>