在MySQL中计算数字的幂?

要计算数字的幂,请使用POWER()函数。让我们首先创建一个表-

create table DemoTable
   (
      Amount int
   );

使用插入命令在表中插入一些记录-

insert into DemoTable values(64);
insert into DemoTable values(144);
insert into DemoTable values(400);

使用select语句显示表中的所有记录-

select *from DemoTable;

这将产生以下输出-

+--------+
| Amount |
+--------+
| 64     |
| 144    |
| 400    |
+--------+
3 rows in set (0.00 sec)

以下是计算数字幂的查询-

mysql− select Amount,power(Amount,2) AS CURRENT_AMOUNT from DemoTable;

这将产生以下输出-

+--------+----------------+
| Amount | CURRENT_AMOUNT |
+--------+----------------+
| 64     | 4096           |
| 144    | 20736          |
| 400    | 160000         |
+--------+----------------+
3 rows in set (0.04 sec)