• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
泛舟
欲穷千里目,更上一层楼
博客园    首页    新随笔    联系   管理    订阅  订阅

存储过程练习

CREATE PROCEDURE Web_GetRank
@TeamID  int ,   --组别
@Num  int ,  --提取前几名
@Accounts varchar(31)= '**'   --查询的账号
WITH ENCRYPTION
AS

if  exists (select UserID 
from GameScoreInfo
where UserID not in (select UserID from MatchScoreStat) )
begin
insert into MatchScoreStat( UserID) select UserID 
from GameScoreInfo
where UserID not in (select UserID from MatchScoreStat)
end

select a.TeamID, a.Accounts,a.IdentitySerial,b.Score+c.MatchScore TotalScore,
RANK() over (order by b.Score+c.MatchScore desc,
b.WinCount+b.LostCount+b.FleeCount desc,
 ( case  (b.WinCount+b.LostCount+b.FleeCount+b.DrawCount) when 0 then 0 else   b.DrawCount/(b.WinCount+b.LostCount+b.FleeCount+b.DrawCount) end) asc) TotalRank
into #TempTableRank
from MatchUserDetail a ,GameScoreInfo b,dbo.MatchScoreStat c ,MatchUserInfo d
where  a.UserID= b.UserID and b.UserID=c.UserID  and a.UserID=d.UserID and d.StateFlag=0;

if @TeamID =0
begin
select top(@Num) Accounts ,IdentitySerial, TotalScore,TotalRank ,Rank() over (order by TotalRank) RankINGroup from #TempTableRank ;
end
else
begin
select top(@Num) Accounts ,IdentitySerial, TotalScore,TotalRank ,Rank() over (order by TotalRank) RankINGroup from #TempTableRank where TeamID=@TeamID;
end

if @Accounts<>'**'
begin
select @TeamID=  TeamID from MatchUserDetail where Accounts= @Accounts
select top(@Num) Accounts ,IdentitySerial, TotalScore,TotalRank ,Rank() over (order by TotalRank) RankINGroup  into #TempTableRank2 from #TempTableRank where TeamID=@TeamID;
select * from #TempTableRank2 where Accounts= @Accounts
end
go

posted @ 2009-03-02 18:22  7goal  阅读(387)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3