乘以两列的值,并在 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)
广告