Using LOG with data in a table : LOG « Math Numeric Functions « MySQL Tutorial






mysql>
mysql>
mysql> create table myTable(
    ->   id           int(2),
    ->   value        FLOAT(6,2)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> insert into myTable(ID,  value)values (1,9);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (2,2.11);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (3,3.44);
Query OK, 1 row affected (0.02 sec)

mysql> insert into myTable(ID,  value)values (4,-4.21);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (5,10);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (6,3);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (7,-5.88);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (8,123.45);
Query OK, 1 row affected (0.01 sec)

mysql> insert into myTable(ID,  value)values (9,98.23);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (10,938.23);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (11,-984.23);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (12,198.23);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (13,-928.87);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (14,25.37);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (15,-918.3);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (16,9.23);
Query OK, 1 row affected (0.00 sec)

mysql> insert into myTable(ID,  value)values (17,-8.23);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> select * from myTable;
+------+---------+
| id   | value   |
+------+---------+
|    1 |    9.00 |
|    2 |    2.11 |
|    3 |    3.44 |
|    4 |   -4.21 |
|    5 |   10.00 |
|    6 |    3.00 |
|    7 |   -5.88 |
|    8 |  123.45 |
|    9 |   98.23 |
|   10 |  938.23 |
|   11 | -984.23 |
|   12 |  198.23 |
|   13 | -928.87 |
|   14 |   25.37 |
|   15 | -918.30 |
|   16 |    9.23 |
|   17 |   -8.23 |
+------+---------+
17 rows in set (0.00 sec)

mysql>
mysql> select value, LOG(value) from myTable;
+---------+------------------+
| value   | LOG(value)       |
+---------+------------------+
|    9.00 |  2.1972245773362 |
|    2.11 | 0.74668789777036 |
|    3.44 |  1.2354714880192 |
|   -4.21 |             NULL |
|   10.00 |   2.302585092994 |
|    3.00 |  1.0986122886681 |
|   -5.88 |             NULL |
|  123.45 |  4.8158361910706 |
|   98.23 |   4.587311701861 |
|  938.23 |  6.8439951006905 |
| -984.23 |             NULL |
|  198.23 |  5.2894279511491 |
| -928.87 |             NULL |
|   25.37 |  3.2335674066909 |
| -918.30 |             NULL |
|    9.23 |  2.2224589989196 |
|   -8.23 |             NULL |
+---------+------------------+
17 rows in set (0.00 sec)

mysql>
mysql> drop table myTable;
Query OK, 0 rows affected (0.00 sec)

mysql>








21.21.LOG
21.21.1.LOG(X), LOG(B,X): If called with one parameter, this function returns the natural logarithm of X
21.21.2.Using LOG with data in a table