Changes

MySQL Mathematical Functions

1,040 bytes added, 18:22, 24 October 2007
MySQL Arithmetic Functions
</tr>
</table>
 
As with most MySQL functions it is easy to experimenbt with them without having to access data in a table simply using the SELECT statement. For example, to see the PI() function in action:
 
<pre>
mysql> SELECT PI();
+----------+
| PI() |
+----------+
| 3.141593 |
+----------+
1 row in set (0.00 sec)
</pre>
 
To perform a modulo operation:
 
<pre>
mysql> SELECT 4 % 3;
+-------+
| 4 % 3 |
+-------+
| 1 |
+-------+
1 row in set (0.00 sec)
</pre>
 
Or, to raise 2 to the power 3:
 
<pre>
mysql> SELECT POW(2, 3);
+-----------+
| POW(2, 3) |
+-----------+
| 8 |
+-----------+
1 row in set (0.00 sec)
</pre>
 
== Summary ==
 
Given the scientific nature of many of the numeric functions provided with MySQL it is unlikely that many of them get used very much. That said, it is reassuring to know that the capabilities are there if you ever need them.
 
Now that we have looked at text and number manipulation functions we will now move on to look at working with [[Working with Dates and Times in MySQL|dates and times in MySQL]].