如何在列中保存计算选择的结果



如何在列中保存计算选择的结果?我想把乘法的结果保存(写(在表一的一列中,比如表1.total

SELECT table1.quantity * table2.price AS result
FROM table1
LEFT JOIN table2 ON table1.code = table2.code

我想你的意思是:

UPDATE table1 SET total = table1.quantity * table2.price
FROM table1
LEFT JOIN table2 ON table1.code = table2.code

参见此处的示例

您可以使用一个临时表:

SELECT table1.quantity * table2.price AS result INTO #Temp
FROM table1
LEFT JOIN table2 ON table1.code = table2.code

连接关闭后,表'#Temp'将被删除。

有关详细信息,请查看以下网址:https://www.sqlservertutorial.net/sql-server-basics/sql-server-temporary-tables/

最新更新