使用SQL

时间:2016-02-08 17:40:59

标签: sql database

使用SQL我希望将使用select提取的值相乘: 这是一个例子:

SELECT Number1, Number2
FROM myTable
WHERE PrimaryKey = MyPrimaryKey

例如,结果是:3, 4

而我想要获得的是12

所以可以制作这样的东西吗?

SELECT Number1 * Number2
FROM myTable
WHERE PrimaryKey = MyPrimaryKey

2 个答案:

答案 0 :(得分:0)

是的,这是可能的。

SELECT Number1 * Number2
FROM myTable
WHERE PrimaryKey = MyPrimaryKey

答案 1 :(得分:0)

是的你得到了它

mysql> show create table numbers\G
*************************** 1. row ***************************
       Table: numbers
Create Table: CREATE TABLE numbers (
  'id' int(11) NOT NULL,
  'num1' int(11) DEFAULT NULL,
  'num2' int(11) DEFAULT NULL,
  PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

mysql> select * from numbers;
+----+------+------+
| id | num1 | num2 |
+----+------+------+
|  0 |    3 |    4 |
+----+------+------+
1 row in set (0.00 sec)

mysql> select num1 * num2 from numbers where id = 0;
+-------------+
| num1 * num2 |
+-------------+
|          12 |
+-------------+
1 row in set (0.01 sec)