我在经典的asp页面上运行以下查询。
sSQL = "Select ProductID, SUM(Quantity) FROM OrderDetails Where CAST(orderDate AS DATE) Between '"&sStartDate&"' And '"&sEndDate&"' GROUP BY ProductID"
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText
<tr>
<td>
<%Response.Write(rs.Fields("ProductID"))%>
</td>
<td>
What is the code to get the sum of the quantity here?
</td>
如何输出数量?
答案 0 :(得分:6)
sSQL = "Select ProductID, SUM(Quantity) as TotalQuantity FROM OrderDetails Where CAST(orderDate AS DATE) Between '"&sStartDate&"' And '"&sEndDate&"' GROUP BY ProductID"
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText
<tr>
<td>
<%Response.Write(rs.Fields("ProductID"))%>
</td>
<td>
<%= rs.Fields("TotalQuantity") %>
</td>
答案 1 :(得分:3)
您可以使用序号值访问字段
<%= rs.Fields(1) %>
您还可以将sql查询更改为
选择ProductID,SUM(Quantity)As Quantity ...
然后您就可以访问此列名称
<%= rs.Fields(Quantity) %>