我想结合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
%>
答案 0 :(得分: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;
如果您需要结果集中的所有三列
答案 1 :(得分:1)
我认为这会对你有帮助,
SELECT column1, column2, (column1+column2) AS SumColumn FROM Table1
答案 2 :(得分:1)
<%
Set rstest = Server.CreateObject("ADODB.Recordset")
sql = "SELECT SUM(count) + SELECT SUM(lightcount) AS TotalLightCount FROM Records;"
rstest.Open sql, db
%>