zoukankan      html  css  js  c++  java
  • 写了好半天的有史以来写过的最长的存储过程

    费尽心里写了好半天的有史以来写过的最长的存储过程,不是什么机密的东西,贴在这里,以资纪念,:)
     1CREATE PROCEDURE dbo.list_taoke    
     2AS
     3    /* SET NOCOUNT ON */ 
     4    delete from taokee_Temp
     5    
     6    declare @uid int;/*用户ID*/
     7    declare @exp_count decimal/*被淘的文章数量*/
     8    declare @persent decimal ;/*被淘率*/
     9    declare @info_count decimal;/*发布的文章数量*/
    10    
    11    /*以下循环*/
    12    declare  cursor_Userid cursor  for
    13        select author from info where (infolawid>0and (exp>=2group by author
    14    open cursor_Userid
    15    begin
    16        FETCH NEXT FROM cursor_Userid
    17        INTO @uid
    18        WHILE @@FETCH_STATUS = 0
    19        BEGIN
    20            set @exp_count=select count(*from info where author=@uid and exp>2)
    21            set @info_count = (select count(*from info where author=@uid )
    22            set @persent = (@exp_count/@info_count)*100
    23            insert into taokee_Temp(uid,exp_count,persent,info_count) values (@uid,@exp_count,@persent,@info_count)
    24            FETCH NEXT FROM cursor_Userid
    25            INTO @uid
    26        END
    27    end
    28    close cursor_Userid
    29    deallocate cursor_Userid    
    30    RETURN
    31
    32GO
    33


    更新于: 2006年11月22日 下午
    发现上面的存储过程可以被一句SQL取代,如下:
    select top 50 * from 

    select  distinct author as uid ,info_count=(select count(0from info where info.author=t.author ),
    exp_count
    =(select count(0from info where info.author=t.author and exp>2)
     
    from info t where infolawid>0  
    as x order by x.exp_count desc
  • 相关阅读:
    Swing程序最佳架构设计—以业务对象为中心的MVC模式(转)
    股市投资策略总结(转)
    php学习笔记--高级教程--读取文件、创建文件、写入文件
    史上最简单的Hibernate入门简单介绍
    Java中StringBuilder的清空方法比較
    DHCP Option 60 的理解
    ICMP报文分析
    软件測试自学指南---从入门到精通
    Qt多线程学习:创建多线程
    Bulk Insert命令具体
  • 原文地址:https://www.cnblogs.com/lbk/p/512791.html
Copyright © 2011-2022 走看看