世界杯猜想活动的各类榜单的SQL语句小结


/*增幅降幅排名*/

复制代码 代码如下:

Select top 50 UserName,sum(ReceivePrice) - sum(GuessPrice) as ReceivePrice,
cast(sum(CASE WHEN ReceivePrice>0 THEN 1.0 ELSE 0 END) / count(ReceivePrice) * 100 as numeric(4,1)) as Rate
From [game_FantasyLog]
WHERE IsJudge=1
GROUP BY UserId,UserName
ORDER BY sum(ReceivePrice) - sum(GuessPrice) ASC

/*正确率错误率排名*/
复制代码 代码如下:

Select top 50 UserName,sum(ReceivePrice) - sum(GuessPrice) as ReceivePrice,
cast(sum(CASE WHEN ReceivePrice>0 THEN 1.0 ELSE 0 END) / count(ReceivePrice) * 100 as numeric(4,1)) as Rate
From [game_FantasyLog]
WHERE IsJudge=1
GROUP BY UserId,UserName Having count(UserId) >= 5
ORDER BY cast(sum(CASE WHEN ReceivePrice>0 THEN 1.0 ELSE 0 END) / count(ReceivePrice) * 100 as numeric(4,1)) ASC

/*大手笔排名*/
复制代码 代码如下:

Select top 50 l.UserName,sum(l.GuessPrice),sum(l.ReceivePrice),f.title
From [game_FantasyLog] l left join [game_fantasy] f on l.topicid = f.id
GROUP BY l.TopicId,l.UserName,f.title
ORDER BY sum(l.GuessPrice) DESC

/*冷门场次排名*/
复制代码 代码如下:

Select top 50 f.id,f.title,f.GuessPrice,(select sum(receivePrice) FROM [game_FantasyLog] l where l.topicid = f.id),
cast((select sum(CASE WHEN ReceivePrice>0 THEN 1.0 ELSE 0 END) / f.GuessTimes FROM [game_FantasyLog] l2 where l2.topicid = f.id) as numeric(4,2))
From [game_Fantasy] f WHERE f.GuessPrice > 1000
ORDER BY (select sum(receivePrice) FROM [game_FantasyLog] l where l.topicid = f.id) ASC

/*冷门场次的命中者*/
复制代码 代码如下:

Select top 50 UserName,sum(ReceivePrice) as ReceivePrice
From [game_FantasyLog] where topicid=29
GROUP BY TopicId,UserName
ORDER BY sum(ReceivePrice) DESC



相关阅读:
模拟用户操作Input元素,不会触发相应事件
Windows Server 2008服务器系统数据安全
PHP3 safe_mode 失效漏洞
监视并记录Apache网站服务器的运行
ASP.NET MVC框架内置AJAX支持编程技术
asp 实现对SQL注入危险字符进行重编码处理的函数
用户体验第一 font-size放弃px选择em
简单学习认识HTML5标签
ASP.NET程序防范SQL注入式攻击的方法
PHP下10件你也许并不了解的事情
CSS实现样式布局实用技巧大集合
ASP.NET编译执行常见错误及解决方法汇总
Ubuntu的虚拟控制台实现中文
Oracle用户权限分配方法介绍
快速导航

Copyright © 2016 phpStudy | 皖ICP备18014864号-4