无法在mysql的SELECT语句中创建别名

时间:2017-09-09 08:25:51

标签: mysqli

在SELECT中创建别名时遇到错误:“字段列表”中的未知列'totval'。这是我的mysql查询

"INSERT INTO `currentweekvalue` (symbol,value)
SELECT `currentweekvalue`.symbol as csymbol, (`currentweekvalue`.value + $dayiterated.value) as `totval` 
FROM `currentweekvalue`
LEFT JOIN $dayiterated ON `currentweekvalue`.symbol = $dayiterated.symbol 
WHERE `currentweekvalue`.symbol = $dayiterated.symbol
ON DUPLICATE KEY UPDATE value = VALUES(totval)";

我试着将它封装在另一个SELECT上无济于事:

"INSERT INTO `currentweekvalue` (symbol,value)
SELECT * FROM (SELECT `currentweekvalue`.symbol as csymbol, (`currentweekvalue`.value + $dayiterated.value) as totval
FROM `currentweekvalue`  
LEFT JOIN $dayiterated ON `currentweekvalue`.symbol = $dayiterated.symbol) t
WHERE `currentweekvalue`.symbol = $dayiterated.symbol
ON DUPLICATE KEY UPDATE value = VALUES(t.totval)";      

先谢谢

0 个答案:

没有答案