要返回一個數字的另一個冪的值,我們應該在 MySQL 中使用 ^ 運算子嗎?


不,^是 MySQL 中的位異或運算子。為此,請使用 MySQL 中的 POW() 或 POWER()。讓我們首先建立一個表 &minuns;

mysql> create table DemoTable
(
   BaseValue int,
   PowerValue float
);
Query OK, 0 rows affected (0.48 sec)

使用 insert 命令在表中插入一些記錄 −

mysql> insert into DemoTable values(4,1.9867);
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values(10,6.789);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values(20,8.9);
Query OK, 1 row affected (0.14 sec)

使用 select 語句顯示錶中的所有記錄 −

mysql> select *from DemoTable;

這會產生以下輸出 −

+-----------+------------+
| BaseValue | PowerValue |
+-----------+------------+
|         4 | 1.9867     |
|        10 | 6.789      |
|        20 | 8.9        |
+-----------+------------+
3 rows in set (0.00 sec)

以下是返回一個數字的另一個冪值的查詢。在此處,基礎值和冪值由我們上面插入 −

mysql> select power(BaseValue,PowerValue) AS Result from DemoTable;

這會產生以下輸出 −

+--------------------+
| Result             |
+--------------------+
| 15.707700779637127 |
| 6151769.213414385  |
| 379460404302.3042  |
+--------------------+
3 rows in set (0.00 sec)

更新於: 04-10-2019

70 次檢視

開始你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.