0
我需要爲結果數學函數乘法創建一個視圖。這可能嗎?MySQL Math - 從另一列計算值
表:
mysql> show create table devices \G
Create Table: CREATE TABLE `devices` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`d_type` varchar(255) NOT NULL,
`multiplier` char(255) NOT NULL DEFAULT '',
`value` decimal(10,3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
示例行:
mysql> SELECT devices.id, devices.d_type, devices.multiplier, devices.`value` FROM devices;
+----+--------------------------+------------+--------+
| id | d_type | multiplier | value |
+----+--------------------------+------------+--------+
| 1 | Cisco Call Manager |/ | 4.000 |
| 2 | Generic Router/Switch | * | 0.350 |
我需要使用乘法器,提供各種數學結果以某種方式計算。 實施例(不工作當然):
SELECT devices.id, devices.d_type, devices.multiplier, devices.`value`, (SELECT 1 $multiplier devices.`value`) as EPS FROM devices;
在這種情況下,結果應該是:
+----+--------------------------+------------+--------+--------+
| id | d_type | multiplier | value | EPS |
+----+--------------------------+------------+--------+--------+
| 1 | Cisco Call Manager |/ | 4.000 | 0.25 |
| 2 | Generic Router/Switch | * | 0.350 | 0.35 |
我們需要通過分割或由值列乘以1以導出EPS柱。 有沒有辦法使用乘數作爲是否分割或乘法的決心?
(請注意,我用了1爲例,這可能是根據用戶輸入的任何傳入整數)
謝謝!爲了保持完整性,以防某些人稍後需要時出現語法錯誤。這裏是正確的命令:'SELECT devices.id,devices.d_type,devices.multiplier,devices.value,(IF(multiplier ='/',1/value,1 * value))AS EPS FROM devices;' – 2012-08-16 05:18:18