将两列的值相乘并在MySQL中将其显示为新列?
让我们首先创建一个表-
mysql> create table DemoTable -> ( -> NumberOfItems int, -> Amount int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(4,902); mysql> insert into DemoTable values(5,1000); mysql> insert into DemoTable values(3,80);
使用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)