Math Numeric Functions MySQL Tutorial

If called with two parameters, this function returns the logarithm of X for an arbitrary base B.

mysql>
mysql> SELECT LOG(2,65536);
+--------------+
| LOG(2,65536) |
+--------------+
|           16 |
+--------------+
1 row in set (0.00 sec)
mysql> SELECT LOG(10,100);
+-------------+
| LOG(10,100) |
+-------------+
|           2 |
+-------------+
1 row in set (0.01 sec)
mysql>
LOG(B,X) is equivalent to LOG(X) / LOG(B).
mysql>

mysql>
mysql> SELECT LOG2(65536);
+-------------+
| LOG2(65536) |
+-------------+
|          16 |
+-------------+
1 row in set (0.00 sec)
mysql>
mysql> SELECT LOG2(-100);
+------------+
| LOG2(-100) |
+------------+
|       NULL |
+------------+
1 row in set (0.00 sec)
mysql>