Here are some examples of arithmetic in MySQL. They are fairly self explanatory but there are a few points to note:
- You can select pi directly.
- The square root of -2 gives the answer -NaN. NaN stands for Not a Number.
- The order of precedence seems to be fairly standard and you can alter it by using brackets.
mysql> select 5+3/2, (5+3)/2;
+--------+---------+
| 5+3/2 | (5+3)/2 |
+--------+---------+
| 6.5000 | 4.0000 |
+--------+---------+
1 row in set (0.00 sec)
mysql> select pi();
+----------+
| pi() |
+----------+
| 3.141593 |
+----------+
1 row in set (0.00 sec)
mysql> select power(2,3), power(4,0.5);
+------------+--------------+
| power(2,3) | power(4,0.5) |
+------------+--------------+
| 8 | 2 |
+------------+--------------+
1 row in set (0.00 sec)
mysql> select power(-2,0.5);
+---------------+
| power(-2,0.5) |
+---------------+
| -NaN |
+---------------+
1 row in set (0.00 sec)
mysql> select power(-3,2);
+-------------+
| power(-3,2) |
+-------------+
| 9 |
+-------------+
1 row in set (0.00 sec)
mysql>
No comments:
Post a Comment