乘以兩列的值,並在 MySQL 中將它顯示為新列?


我們先建立一個表 −

mysql> create table DemoTable
   -> (
   -> NumberOfItems int,
   -> Amount int
   -> );
Query OK, 0 rows affected (0.57 sec)

在表中插入一些記錄 −

mysql> insert into DemoTable values(4,902);
Query OK, 1 row affected (0.45 sec)

mysql> insert into DemoTable values(5,1000);
Query OK, 1 row affected (0.16 sec)

mysql> insert into DemoTable values(3,80);
Query OK, 1 row affected (0.12 sec)

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

mysql> select *from DemoTable;

輸出

+---------------+--------+
| NumberOfItems | Amount |
+---------------+--------+
|             4 | 902    |
|             5 | 1000   |
|             3 | 80     |
+---------------+--------+
3 rows in set (0.00 sec)

以下是用於操作資料庫的查詢 −

mysql> select NumberOfItems,Amount,(NumberOfItems*Amount) AS PayableAmount from DemoTable;

輸出

+---------------+--------+---------------+
| NumberOfItems | Amount | PayableAmount |
+---------------+--------+---------------+
|             4 | 902    |         3608  |
|             5 | 1000   |         5000  |
|             3 | 80     |         240   |
+---------------+--------+---------------+
3 rows in set (0.00 sec)

更新時間: 30-7-2019

3K+ 瀏覽量

開啟您的生涯

完成課程並獲得認證

開始
廣告
© . All rights reserved.