如何对 SQL 中的列求和?

how to sum a column in SQL?

我将视图的两列相乘 vDetalleEventoCaracteristicas 并将其显示在“总计”列中,但现在我想对“总计”列的所有记录求和

我该怎么做?

SELECT SUM(Total) AS Total_Sum
FROM (
    SELECT *,(Cantidad * valor) AS Total
    FROM vDetalleEventoCaracteristicas
    WHERE idevento = @IdEvento
)table_alis

使用此查询您将获得总计列的总和。

只需将 SUM 添加到您的 select 语句中:

select SUM(Cantidad * Valor) AS Total from vDetalleEventoCaracteristicas
where  idevento = @IdEvento