建站代码网

热门标签

SQL: 总数,平均数,最大值,最小值,数值,详情

有很多你可以演示带有简单sql的数据的统计数据。总数,平均数,最大值,最小值和几乎和演示你的完整数据详情一样容易派生的数值。下面的例子利用到了我们的EPOS (@PointofSale.com)股票交易性能数据库(交易日,收盘价和成交量)。每个统计数据在一个下拉菜单下都是有用的,在成交量里用到的sql是能显示出来的。

<% u_title=request.form("u_title")
‘检查看看用户是否输入了要显示的统计值。
‘如果是无效值那跳转到查询数据库,仅显示输入表单

if u_title<>"" then select case u_title
‘所有的有用的sql都来自于列出的下拉菜单

case "Average" sql = "select avg(volume) as vol from epos" case "Min" sql = "select min(volume) as vol from epos;" case "Max" sql = "select max(volume) as vol from epos;" case "Sum" sql = "select sum(volume) as vol from epos;" case "Count" sql = "select count(volume) as vol from epos;" case "Detail" sql = "select volume as vol from epos;" end select accessdb="stocks" cn="DRIVER={Microsoft Access Driver (*.mdb)};" cn=cn & "DBQ=" & server.mappath(accessdb) Set rs = Server.CreateObject("ADODB.Recordset") rs.Open sql, cn %> <body bgcolor="#FFFFFF"> <title><%= sql %></title> <table border="0" align="center" width="100%"> <tr><td align="center"> <p><%= sql %></p> <table border="5" cellpadding="3" cellspacing="3" align="center"> <tr> <td> Volume<br>(<%= u_title %>) </td> </tr> <% rs.movefirst do while not rs.eof %> <tr> <td> <%= formatnumber(rs("vol"),0) %> </td> </tr> <% rs.movenext loop %> </table> <% end if %> <form action="<%= request.servervariables("script_name") %>" method="post"> <% if u_title = "" then %> <table align="center"><tr><td>Please make a selection<br> <% end if %> <select name="u_title" size="1"> <% if u_title <> "" then %> <option selected value="<%= u_title %>"><%= u_title %></option> <% end if %> <option value="Average">Average</option> <option value="Max">Max</option> <option value="Min">Min</option> <option value="Sum">Sum</option> <option value="Count">Count</option> <option value="Detail">Detail</option> </select><br><br> <input type="submit" value="Submit"> </form><br> </td></tr></table> </td></tr></table>


热门信息

X