数据库内容 编号id,金额jine,类别leibie
假如我类别(leibie)里面内容只是‘零售’的金额加起来
<!-- #include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<table border="1" bordercolor="#000000">
<tr>
<td width="86">ID</td>
<td width="92">jine</td>
</tr>
<%
keyword="高妹"
'数据库连接代码略,得根据你实际情况来
Set rs=Server.createobject("adodb.recordset")
sql="select * from eee where biaoji like '%"&keyword&"%'"
rs.open sql,conn,1,1
do while not rs.eof
%>
<tr>
<td><%=rs("id")%></td>
<td><%=rs("jine")%></td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
Set rs2 = conn.execute("select sum(jine) from eee")
heji=rs2(0)
Set rs = nothing
%>
<tr><td colspan="2"><%=heji%></td></tr>
</table>
</body>
</html>
望高手指点
<!-- #include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<table border="1" bordercolor="#000000">
<tr>
<td width="86">ID</td>
<td width="92">jine</td>
</tr>
<%
keyword="高妹"
'数据库连接代码略,得根据你实际情况来
Set rs=Server.createobject("adodb.recordset")
sql="select * from eee where biaoji like '%"&keyword&"%'"
rs.open sql,conn,1,1
dim i=0
do while not rs.eof
if rs("leibie")="零售" then
i=i+rs("jine") 'i就是类别为‘零售’产品的价格和
end if
%>
<tr>
<td><%=rs("id")%></td>
<td><%=rs("jine")%></td>
</tr>
<%
rs.movenext
loop
rs.close
set rs=nothing
Set rs2 = conn.execute("select sum(jine) from eee")
heji=rs2(0)
Set rs = nothing
%>
<tr><td colspan="2"><%=heji%></td></tr>
</table>
</body>
</html>
SQL有问题。
一句SQL:
select id,jine from eee union select '零售总额' id,sum(jine) jine from eee where leibie='零售'
sql="select sum(jine) from eee where biaoji like '%"&keyword&"%' and leibie='零售'"
rs.open sql,conn,1,1
if rs.recordCount>0 and not isNull(RS(1)) Then
Response.write "<td clospan=2>" & RS(0) & "</td>"
End IF
RS.close