Skip to main content
VeloDB Cloud 26.x·Apache Doris 4.x (≤ 4.0 supported)·"Since X.Y" tags refer to Doris versionsversion mapping →

GCD

Description

Calculates the greatest common divisor (GCD) of two integers.

Syntax

GCD(<a>, <b>)

Parameters

ParameterDescription
<a>The first integer
<b>The second integer

Return Value

Returns the greatest common divisor of <a> and <b>. If any input is NULL, returns NULL.

Examples

select gcd(54, 24);
+------------+
| gcd(54,24) |
+------------+
| 6 |
+------------+
select gcd(-17, 31);
+--------------+
| gcd(-17,31) |
+--------------+
| 1 |
+--------------+
select gcd(0, 10);
+-----------+
| gcd(0,10) |
+-----------+
| 10 |
+-----------+
select gcd(54, NULL);
+---------------+
| gcd(54, NULL) |
+---------------+
| NULL |
+---------------+