asp的问题,求教

来源:百度知道 编辑:UC知道 时间:2024/06/21 18:47:20
如:<%=rs("title")%>为日期,每天产量为<%=rs("title2")%>,搜索title日期为2008-5有N条,
求:2008-5的总产量、2008-5的平均值,
在网上请教高人指点如下:
'总产量
TEMP1=Conn.execute("Select Sum(title2)from [产量表] where title='2008-5'")(0)
if isnull(temp1) then temp1=0 end if

'平均
TEMP2=Conn.execute("Select Avg(title2)from [产量表] where title='2008-5'")(0)
if isnull(temp2) then temp2=0 end if

这个值得到的是2008-5平均值、总产量都求来了,
新问题,我现在怎么实现“title”随意变;

你可以做一个搜索表单,提交以后显示符合条件的记录

<form name="form1" action="" method="post">
<input type="text" name="title">
<input type="submit" value="搜索">
</form>

<%
title = trim(request.form("title"))
if title<>"" then
'总产量
TEMP1=Conn.execute("Select Sum(title2)from [产量表] where title='"&title&"'")(0)
if isnull(temp1) then temp1=0 end if

'平均
TEMP2=Conn.execute("Select Avg(title2)from [产量表] where title='"&title&"'")(0)
if isnull(temp2) then temp2=0 end if

end if
%>

var theTitle = rs("title");
TEMP1=Conn.execute("Select Sum(title2)from [产量表] where title='&theTitle&'")(0)
if isnull(temp1) then temp1=0 end if

平均一样,改where条件即可.
希望能帮到你.