|
蓝森林 http://www.lslnet.com 2006年8月25日 8:28
sql求和的问题
我想在最后一页显示“金额”的总和,不知道该怎么弄?
<!--#INCLUDE FILE="conn.inc" -->
<TABLE border=1 cellPadding=2 cellSpacing=1 width="561">
<TBODY>
<TR bgColor=#999999>
<TD class=heading colspan=2 width="367">
<TABLE border=1 cellPadding=0 cellSpacing=0 width="128%">
<TBODY>
<TR> <TD align=right width="2%"> </TD><TD align=right>
<%
dim page
page=request("page")
PageSize =6
dim rs,sql
sql ="select * from qcyeb order by wplb"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,Conn,1,3
rs.PageSize = PageSize
totalfilm=rs.recordcount
pgnum=rs.Pagecount
if page="" or clng(page)<1 then page=1
if clng(page) > pgnum then page=pgnum
if pgnum>0 then rs.AbsolutePage=page
if rs.eof then
response.write "<font color='#ffffff' class='3dfont'>还没有记录</font>"
else
%>
<table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <FONT COLOR="#ffffff">
[<b><%=rs.pagecount%></b>/<%=page%>页] [共<%=totalfilm%>个] <%if page=1 then%> [首
页] [上一页] <% else %> [<a href="1.asp?page=1">首 页</a>] [<a href="1.asp?page=<%=page-1%>">上一页</a>]<%end if%><%if rs.pagecount-page<1 then%>
[下一页] [尾 页] <%else%> [<a href="1.asp?page=<%=page+1%>">下一页</a>] [<a href="1.asp?page=<%=rs.pagecount%>">尾
页</a>]</FONT> <%end if%>
</td> </tr>
</table></TD><TD width="3%"></TD></TR> </TBODY> </TABLE></TD></TR>
<TR >
<TD ><b>库存数量</b></TD>
<TD ><b>单价</b></TD>
<TD ><b>金额</b></TD>
</TR>
<%
count=0
do while not (rs.eof or rs.bof) and count<rs.PageSize
%>
<TR>
<td ><%=rs("kcsl")%> </td>
<td ><%=rs("bhsdj")%></td>
<td ><%=rs("bhsjer")%></td>
</TR>
<%rs.movenext
count=count+1
loop
end if%>
</TBODY> </TABLE></TBODY></TABLE> |
<%
dim allxx
allxx=0
count=0
do while not (rs.eof or rs.bof) and count<rs.PageSize
%>
<%allxx=allxx+rs("总数")%>
<%rs.movenext
count=count+1
loop
Response.write("总数"&allxx)
end if%>
|
<%Set rs1 = Server.CreateObject("ADODB.Recordset")
sql1="select sum(bhsjer) from qcyeb"
rs1.open sql1,Conn,1,3
%>
<td>合计:<input type="text" value="<%=rs1(0)%>"></td>
这样就可以求和了,可是现在每一页都显示合计,我想在最后一页显示合计,不要每一页都有。 |
dim 页码
页码=Request.Querystring("页码")
if 页码="" or 页码=1 then
显示合
Enf if |
终于好了。
<!--#INCLUDE FILE="conn.inc" -->
<TABLE border=1 cellPadding=2 cellSpacing=1 width="561">
<TBODY>
<TR bgColor=#999999>
<TD class=heading colspan=2 width="436">
<TABLE border=1 cellPadding=0 cellSpacing=0 width="128%">
<TBODY>
<TR> <TD align=right width="2%"> </TD><TD align=right>
<%
dim page
page=request("page")
PageSize =4
dim rs,sql
sql ="select * from qcyeb order by wplb"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,Conn,1,3
rs.PageSize = PageSize
totalfilm=rs.recordcount
pgnum=rs.Pagecount
if page="" or clng(page)<1 then page=1
if clng(page) > pgnum then page=pgnum
if pgnum>0 then rs.AbsolutePage=page
if rs.eof then
response.write "<font color='#ffffff' class='3dfont'>还没有记录</font>"
else
%>
<table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <FONT COLOR="#ffffff">
[<b><%=rs.pagecount%></b>/<%=page%>页] [共<%=totalfilm%>个] <%if page=1 then%> [首
页] [上一页] <% else %> [<a href="1.asp?page=1">首 页</a>] [<a href="1.asp?page=<%=page-1%>">上一页</a>]<%end if%><%if rs.pagecount-page<1 then%>
[下一页] [尾 页] <%else%> [<a href="1.asp?page=<%=page+1%>">下一页</a>] [<a href="1.asp?page=<%=rs.pagecount%>">尾
页</a>]</FONT> <%end if%>
</td> </tr>
</table></TD><TD width="3%"></TD></TR> </TBODY> </TABLE></TD></TR>
<TR >
<TD width="295" ><b>数量</b></TD>
<TD width="134" ><b>单价</b></TD>
<TD width="108" ><b>金额</b></TD>
</TR>
<%
count=0
do while not (rs.eof or rs.bof) and count<rs.PageSize
%>
<TR>
<td width="295" ><%=rs("kcsl")%> </td>
<td width="134" ><%=rs("bhsdj")%></td>
<td width="108" ><%=rs("bhsjer")%></td>
</TR>
<%rs.movenext
count=count+1
loop
end if%><%Set rs1 = Server.CreateObject("ADODB.Recordset")
sql1="select sum(bhsjer) from qcyeb"
rs1.open sql1,Conn,1,3
%>
</TBODY> </TABLE></TBODY></TABLE>
<%if cint(pgnum)=cint(page) then
response.write" 合计:"&rs1(0)&""
end if
%> |
|