MySQL Tutorial/Math Numeric Functions/EXP

Материал из SQL эксперт
Перейти к: навигация, поиск

EXP(X) returns the value of e (the base of natural logarithms) raised to the power of X

mysql>
mysql>
mysql> SELECT EXP(2);
+-----------------+
| EXP(2)          |
+-----------------+
| 7.3890560989307 |
+-----------------+
1 row in set (0.00 sec)
mysql> SELECT EXP(-2);
+------------------+
| EXP(-2)          |
+------------------+
| 0.13533528323661 |
+------------------+
1 row in set (0.00 sec)
mysql> SELECT EXP(0);
+--------+
| EXP(0) |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)
mysql>


Using EXP function with data in a table

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.00 sec)
mysql> insert into myTable(ID,  value)values (4,-4.21);
Query OK, 1 row affected (0.01 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.00 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>
mysql>
mysql> select value, EXP(value) from myTable;
+---------+----------------------+
| value   | EXP(value)           |
+---------+----------------------+
|    9.00 |      8103.0839275754 |
|    2.11 |      8.2482404193518 |
|    3.44 |      31.186959952842 |
|   -4.21 |    0.014846367771743 |
|   10.00 |      22026.465794807 |
|    3.00 |      20.085536923188 |
|   -5.88 |   0.0027947849551991 |
|  123.45 | 4.1082083938205e+053 |
|   98.23 |   4.57876564137e+042 |
|  938.23 |               1.#INF |
| -984.23 |                    0 |
|  198.23 | 1.2308164504724e+086 |
| -928.87 |                    0 |
|   25.37 |      104244072681.15 |
| -918.30 |                    0 |
|    9.23 |      10198.536843185 |
|   -8.23 |   0.0002665364522633 |
+---------+----------------------+
17 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql>
mysql> drop table myTable;
Query OK, 0 rows affected (0.02 sec)
mysql>
mysql>