Use the POW() function to raise the Amount values by a power of 2. : Power « Math « SQL / MySQL






Use the POW() function to raise the Amount values by a power of 2.

   
mysql>
mysql> CREATE TABLE Test
    -> (
    ->     TestID SMALLINT NOT NULL PRIMARY KEY,
    ->     Amount SMALLINT NOT NULL
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO Test VALUES
    -> (101, 12),
    -> (102, 1),
    -> (103, 139),
    -> (104, -37),
    -> (105, 0),
    -> (106, -16);
Query OK, 6 rows affected (0.00 sec)
Records: 6  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> SELECT TestID, Amount, POW(Amount, 2) AS Raised2
    -> FROM Test
    -> ORDER BY TestID;
+--------+--------+---------+
| TestID | Amount | Raised2 |
+--------+--------+---------+
|    101 |     12 |     144 |
|    102 |      1 |       1 |
|    103 |    139 |   19321 |
|    104 |    -37 |    1369 |
|    105 |      0 |       0 |
|    106 |    -16 |     256 |
+--------+--------+---------+
6 rows in set (0.00 sec)

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

   
    
    
  








Related examples in the same category

1.Use power
2.POW(, )