SQL语句构成记录集的各类操作教案实例.doc
文本预览下载声明
SQL语句构成记录集的各类操作教案实例 课 题:SQL语句构成、记录集的各类操作目 的 要 求:1、掌握SQL查询、统计语句的构成;2、掌握记录集的各类操作重点 及难点:SQL查询、统计语句的构成。教 学 方 法: 讲授、练习、示例。教 具:多媒体教室课 时: 4个课时课堂练习:提供的例子:提供的例子:03级毕业设计《家庭财务管理网站》一、作品改进1、问题提出(1)代码共享方面有什么改进?用include 或 iframe提高代码的共享程度(2)数据库设计有什么改进?原来只能容入一个家庭的财务数据,改为可以同时管理多个家庭的财务数据。以家庭用户ID为主线索,分别串联起各个家庭的财务数据。E-R图:(3)家庭财务数据查询、统计如何改进?用户登陆成功后,必须保存用户ID字段的值到Session(UserId)各个查询的条件必须加上用户ID字段的判断条件用SQL本身提供的函数进行分组统计如:sum() avg() count() 等2、利用SQL本身提供的函数进行数据分组统计(1)费用类型分组统计dim useriduserid = Session(UserId)sql= select PayType,sum(Money) as totalAmt from PayList _where 用户ID =#39;amp; userid amp;#39; and year(Time)=#39;amp;nianamp;#39; and _month(Time)=#39;amp;yeamp;#39; group by PayType或sql= select PayType, totalAmt from费用类型分组统计 _where 用户ID =#39;amp; userid amp;#39; and fyear=#39;amp;nianamp;#39; and _fmonth=#39;amp;yeamp;#39;(2)月收入合计sql= select sum(Money) as totalMonAmt1 from PayList _where 用户ID =#39;amp; userid amp;#39; and year(Time)=#39;amp;nianamp;#39; and _month(Time)=#39;amp;yeamp;#39; and InOut=1或sql= select totalAmt from PayList _where 用户ID =#39;amp; userid amp;#39; and InOut=1 and fyear=#39;amp;nianamp;_#39; and fmonth=#39;amp;yeamp;#39;(3)月支出合计sql= select sum(Money) as totalMonAmt0 from PayList _where 用户ID =#39;amp; userid amp;#39; and year(Time)=#39;amp;nianamp;#39; and _month(Time)=#39;amp;yeamp;#39; and InOut=0或sql= select totalAmt from PayList _where 用户ID =#39;amp; userid amp;#39; and InOut=0 and fyear=#39;amp;nianamp;_#39; and fmonth=#39;amp;yeamp;#39;3、模糊查询在整站查找中的运用sql = select * from arctilce where title = #39;%amp; sztitle amp;%#39;或sql = select * from arctilce where amp; szField amp; = #39;%amp; sztitle amp;%#39;在fyll.asp例子中:构造SQL查询时,对项目名称栏目中的内容进行模糊查询:sqltext = sqltext amp; and Project like #39;%amp;pjnameamp;%#39;二、记录集的各类操作以tj.asp为例:lt;% #39;动态地设置选项列表中各项内容,内容来自数据库表。Dim pa,ptSet pa=Conn.Execute(Select Payer From [Payer])Do While Not pa.EofResponse.write lt;option value=#39; amp; pa(0) amp; #39;gt; amp; pa(0) amp; lt;/optiongt;pa.MoveNextLooppa.CloseSet pa=Nothing%
显示全部