1.【需求】
表中存储着页面的点击次数如下:
名字varchar2    点击次数number     时间varchar2  备注varchar2
index.htm            2              20020619    
index.htm            4              20020616
index.htm            5              20020610
index.htm            23             20020617
1.htm                2              20020619
1.htm                2              20020616
1.htm                3              20020610
要求列出某一名字在指定时间段的每天点击次数,如下:
列出'index.htm'在20020610-20020619间的每天点击次数
要求:
20020619   2
20020618   0
20020617   23
20020616   4
20020615   0
20020614   0
20020613   0
20020612   0
20020611   0
20020610   5【问题】
请注意数据表里只有10、16、17、19这几天的点击次数……
要求使用SQL语句要按照时间的顺序输出……2.一百个账户各有100$,某个账户某天如有支出则添加一条新记录,记录其余额。
问题:1、一百天后,请输出每天所有账户的余额信息。
      2、开发存储过程,查询一百天内任意时间点的余额情况。
       可自定义数据库结构,将运算过程、算法书写清楚。

解决方案 »

  1.   

    1:
    create table test(名字 varchar(50),点击次数 int,时间 varchar(20),备注 varchar(20))
    insert into test(名字,点击次数,时间)
    select 'index.htm',2,'20020619' union all 
    select 'index.htm',4,'20020616' union all
    select 'index.htm',5,'20020610' union all
    select 'index.htm',23,'20020617' union all
    select '1.htm',2,'20020619' union all
    select '1.htm',2,'20020616' union all
    select '1.htm',3,'20020610'
    create table #t(时间 int,点击次数 int)
    declare @i int
    set @i = 20020610
    while @i <= 20020619
    begin
    insert into #t(时间,点击次数)
    select @i,isnull((select 点击次数 from test where cast(时间 as int)= @i and 名字 = 'index.htm'),0)
    set @i = @i + 1
    end
    select * from #t order by 时间 descdrop table test
    drop table #t
      

  2.   

    老兄 我想要SQL语句 不是SQL 帮帮忙好不??
      

  3.   


    create table test(名字 varchar(50),点击次数 int,时间 varchar(20),备注 varchar(20))
    insert into test(名字,点击次数,时间)
    select 'index.htm',2,'20020619' union all 
    select 'index.htm',4,'20020616' union all
    select 'index.htm',5,'20020610' union all
    select 'index.htm',23,'20020617' union all
    select '1.htm',2,'20020619' union all
    select '1.htm',2,'20020616' union all
    select '1.htm',3,'20020610'
    create proc list_all
    (@begin datetime,
    @end datetime)
    as
    begindeclare @t table(时间 datetime,点击次数 int)
    declare @tmp datetime
    set @tmp=@begin 
    while @tmp <dateadd(dd,1,@end)
    begin
    insert into @t values(@tmp,0)
    set @tmp=dateadd(dd,1,@tmp)
    end
    update @t set 点击次数=test.点击次数
    from test ,@t a
    where test.时间=a.时间select * from @t
    endlist_all '20020610','20020619'