在表中添加新列,并在MySQL中用同一表的其他两个列的数据填充它?
让我们首先创建一个表-
mysql> create table DemoTable ( Price int, Quantity int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(45,3); mysql> insert into DemoTable values(90,2); mysql> insert into DemoTable values(440,1);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------+----------+ | Price | Quantity | +-------+----------+ | 45 | 3 | | 90 | 2 | | 440 | 1 | +-------+----------+ 3 rows in set (0.00 sec)
以下是向表中添加新列并填充其他2列数据的查询。在这里,我们添加了新列TotalAmount,其中的数据是前两列的值的乘积-
mysql> select Price,Quantity, Price*Quantity AS TotalAmount from DemoTable;
这将产生以下输出-
+-------+----------+-------------+ | Price | Quantity | TotalAmount | +-------+----------+-------------+ | 45 | 3 | 135 | | 90 | 2 | 180 | | 440 | 1 | 440 | +-------+----------+-------------+ 3 rows in set (0.00 sec)
热门推荐
10 火把节祝福语简短
11 退休祝福语简短独特老师
12 女儿出阁的祝福语简短
13 朋友间上午祝福语简短
14 简短搞笑蛋糕生日祝福语
15 考进高中祝福语简短
16 新郎朋友祝福语简短大气
17 孙子生日祝福语简短精辟
18 集体年会祝福语简短创意