您可以在两个单元格之间使用乘法运算符(*)。语法如下
SELECT yourColumnName1,yourColumnName2, yourColumnName1*yourColumnName2 as ‘anyVariableName’ from yourTableName;
为了理解上述语法,让我们创建一个表。创建表的查询如下
mysql> create table MultiplicationDemo -> ( -> FirstPrice int, -> SecondPrice int -> );
现在,您可以使用insert命令显示表中的所有记录。查询如下
mysql> insert into MultiplicationDemo values(10,2); mysql> insert into MultiplicationDemo values(4,2); mysql> insert into MultiplicationDemo values(5,6); mysql> insert into MultiplicationDemo values(6,3);
使用select语句显示表中的所有记录。查询如下
mysql> select *from MultiplicationDemo;
以下是输出
+------------+-------------+ | FirstPrice | SecondPrice | +------------+-------------+ | 10 | 2 | | 4 | 2 | | 5 | 6 | | 6 | 3 | +------------+-------------+ 4 rows in set (0.00 sec)
这是将两个单元格相乘的查询
mysql> select FirstPrice,SecondPrice, -> FirstPrice*SecondPrice as 'MultiplicationResult' -> from MultiplicationDemo;
以下是输出
+------------+-------------+----------------------+ | FirstPrice | SecondPrice | MultiplicationResult | +------------+-------------+----------------------+ | 10 | 2 | 20 | | 4 | 2 | 8 | | 5 | 6 | 30 | | 6 | 3 | 18 | +------------+-------------+----------------------+ 4 rows in set (0.03 sec)