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
  • 相关阅读:
    浏览器网络相关概念
    量化投资:以python为工具
    Quantitative Strategies for Achieving Alpha (三)
    Quantitative Startegies for Achieving Alpha(二)
    Quantitative Strategies for Achieving Alpha(一)
    打开量化投资的黑箱(二)
    打开量化投资的黑箱(一)
    量化投资学习(一)
    handy源码阅读(六):tcp类
    handy源码阅读(六):udp类
  • 原文地址:https://www.cnblogs.com/lbk/p/512791.html
Copyright © 2011-2022 走看看