-2

我想结合 lightcount 和 TotalLightCount 的总和例如,如果 lightcount = 100 和 TotalLightCount = 300,最终总和将为 400。这是我到目前为止的代码,但我得到的是两个总和而不是一个合计金额。

<%  
Set rstest = Server.CreateObject("ADODB.Recordset")
sql = "SELECT SUM(count) AS TotalCount, SELECT SUM(lightcount) AS TotalLightCount FROM Records;" 
rstest.Open sql, db
%>
4

3 回答 3

2

你在找这个吗?

SELECT SUM(count) + SUM(lightcount) AS GrandTotal 
  FROM Records;

或者

SELECT SUM(count) AS TotalCount, 
       SUM(lightcount) AS TotalLightCount,
       SUM(count) + SUM(lightcount) AS GrandTotal 
  FROM Records;

如果您需要结果集中的所有三列

于 2013-09-18T05:31:10.910 回答
1

我想这会对你有所帮助

SELECT column1, column2, (column1+column2) AS SumColumn FROM Table1
于 2013-09-18T05:38:21.007 回答
1
<%  
Set rstest = Server.CreateObject("ADODB.Recordset")
sql = "SELECT SUM(count) + SELECT SUM(lightcount) AS TotalLightCount FROM Records;" 
rstest.Open sql, db
%>
于 2013-09-18T05:39:04.330 回答