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

推荐订阅源

人人都是产品经理
人人都是产品经理
T
Threatpost
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Recorded Future
Recorded Future
小众软件
小众软件
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
博客园 - 聂微东
美团技术团队
F
Fortinet All Blogs
I
InfoQ
U
Unit 42
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
Vercel News
Vercel News
GbyAI
GbyAI
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
H
Help Net Security
B
Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
Jina AI
Jina AI
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 叶小钗
Recent Announcements
Recent Announcements
D
DataBreaches.Net
IT之家
IT之家
雷峰网
雷峰网
Y
Y Combinator Blog
W
WeLiveSecurity
P
Proofpoint News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
月光博客
月光博客
The Hacker News
The Hacker News

博客园 - fand

ubuntu下wpa_supplicant使用 Google Adsense优化 博文阅读密码验证 - 博客园 测试freebsd上的pf防火墙和linux上的iptables防火墙-zz 安装ffmpeg FreeBSD6安装之AMP的安装 - fand - 博客园 MySQL的性能调优工具:比mysqlreport更方便的tuning-primer.sh 支撑1000万pv的数据库缓存解决方案 博文阅读密码验证 - 博客园 Boost 库中的实用工具类使用 梦断代码 老生常谈 LAMP 系统性能调优 基于反相代理的Web缓存加速——可缓存的系统设计 LDAP介绍 CVS使用手册 学习Java需要达到的30个目标 editplus使用技巧 linux平台使用oracle 9I数据库 PHP程序优化探密
mysql分别排名
fand · 2010-09-21 · via 博客园 - fand

姓名m 科目s 分数n

甲     A     90

甲     B     60

甲     C     70

甲     D     80

乙     A     80

乙     B     80

乙     C     90

丙     A     70

丙     B     80

丁     A     60

如果要得到针对每一个科目ABCD的排名,


mysql里没有rownum,很容易想到子语句
希望早点支持  RANK() OVER。

代码

select n,s,
(
    
select count(1from s_score b where n>=
        (
        
select n
        
from s_score a
        
where and a.s=c.s
        
order by n desc limit 1
        )
    
and b.s=c.s
as r
from s_score c where group by s;

 优化以后

代码

SELECT t3.m, t3.s, max( n ) AS n, count* ) AS r
FROM (SELECT t1.m, t1.s, t1.n
FROM s_score t1, s_score t2
WHERE t2.s = t1.s
AND (
(
t1.n 
< t2.n
)
OR (
(
t1.n 
= t2.n
)
AND (
t1.id 
>= t2.id
)
)
)
ORDER BY t1.m, t1.s
)t3
GROUP BY t3.m, t3.s
ORDER BY n, r