惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Secure Thoughts
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
B
Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
T
The Exploit Database - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
AWS News Blog
AWS News Blog
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
Google Online Security Blog
Google Online Security Blog
T
Troy Hunt's Blog
I
InfoQ
L
LINUX DO - 热门话题
WordPress大学
WordPress大学
C
Cisco Blogs
G
GRAHAM CLULEY
The Register - Security
The Register - Security
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
H
Hacker News: Front Page
小众软件
小众软件
雷峰网
雷峰网
The Hacker News
The Hacker News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
博客园 - 聂微东
N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
The GitHub Blog
The GitHub Blog
腾讯CDC
P
Palo Alto Networks Blog
Scott Helme
Scott Helme

博客园 - Theo

【整理收藏】合并、压缩JS、CSS文件减少页面HTTP请求数的方法 前端要给力之:URL应该有多长? CSS Border使用小分享(转) 发个编程笑话,娱乐一下 sqlserver 生成100万个不重复的10位随机数存入数据库 各种按日期、时间段统计SQL语句 SQL 分析函数over partition 分组数据后取前N条 GridView样式设置 - Theo - 博客园 笔记下UltraEdit的一些常用使用技巧 Web 网页安全色谱 Asp.Net 操作XML基类 警惕采用编码过的SQL恶意注入 .net Repeater无数据时显示"no result" 快速解决方法 生成随机验证码图片程序 javscript 实现iframe加载内容页出现LOADING效果 javascript+ajax控制滑块实现滑杆拉动式评论翻页效果 Gridview 实现 全选多选(支持firefox) C# 实现实时3秒跳转页 - Theo - 博客园 遍历页面上所有TextBox控件并给它的Enabled赋值为false
增加排名列SQL语句(需排名的列值相等时排名相同)
Theo · 2009-11-28 · via 博客园 - Theo

    sql 查询数据时按某列排序后增加排名列,需排名的列值相等时排名相同,即如需排名列数组为:9,9,8,7,7,6

添加的排名列数组需要显示为两种:

  第一种:1,1,3,4,4,6 (这种排名方法应该是最普遍的排名方法啦)   或者

  第二种:1,1,2,3,3,4 (某些特殊情况需要)

 --现在假设测试数据:创建临时表 #score 并插入数据

 create   table   #score(id   int,   points   float)   --id   为学号和points为成绩  
  insert   #score   select   1,   90  
  union       all     select   2,   85  
  union       all     select   3,   83  
  union       all     select   4,   85  
  union       all     select   5,   92 


  --测试得到上述第一种排名显示,SQL如下:  
  Select    
  points,  
  (Select   Count(1)+1   from   #score   Where   points>A.points)   As   排名  
  from   #score   A   Order   By   排名  

 
  --结果如下:  
  /*  

points  排名 
  92.0 1  
  90.0 2  
  85.0 3  
  85.0 3  
  83.0 5  
  */ 符合要求。

 --测试得到上述第二种排名显示,SQL如下:    
  Select    
  points,  
  (Select   Count(Distinct   points)+1   from   #score   Where   points>A.points)   As   排名  
  from   #score   A  
  Order   By   排名   

  --结果  
  /*

points 排名
  92.0 1  
  90.0 2  
  85.0 3  
  85.0 3  
  83.0 4  
  */   符合要求。