在mysql中排名功能 [英] Rank function in mysql
问题描述
先生/妈妈我可以知道如何在我的SQL中获得排名函数
我已经在我的SQL中尝试了这个我尝试过的代码但它的显示错误plz帮助我
SELECT主题,姓名,分数,等级()
结束(按主题分区desc划分)
AS'排名'来自结果;
很多人都说MySQL中没有over子句功能所以我怎样才能获得排名功能先生
我尝试过:
sir/mam can I know how can I get the rank function in my SQL
I have tried in my SQL this the code I have tried but its showing error plz help me
SELECT subjects,names, marks, rank()
over ( partition by subjects order by marks desc )
AS 'rank' FROM result;
many people are saying that there is no over clause function in MySQL so how can i get rank function sir
What I have tried:
SELECT subjects,names, marks, rank()
over ( partition by subjects order by marks desc )
AS 'rank' FROM result;
many people are saying that there is no over clause function in MySQL so how can i get rank function sir
推荐答案
获得正确的语法 - 请参阅文档实践示例的MySQL RANK功能指南 [ ^ ]
试试这个
Just get the syntax right - see the documentation A Guide to MySQL RANK Funtion By Practical Examples[^]
Try this
SELECT subjects,names, marks, rank()
over ( partition by subjects order by marks desc ) my_Rank
FROM result;
我删除了 AS
并为其指定了一个非保留字的名称。
如果它仍然不起作用那么很可能你使用过时版本的MySQL作为很多人,他们说MySQL中没有over子句是错误的。
I've removed the AS
and given it a name that is not a reserved word.
If it still doesn't work then it's likely that you are using an out-of-date version of MySQL as the "many people" who are saying there is no over clause in MySQL are wrong.
根据MySql数据库版本,排名函数可能不可用...请参阅: MySQL :: MySQL 8.0参考手册:: 12.21.1窗口函数说明 [ ^ ]
在这种情况下,请检查:
mysql - 在分数表中获取用户的排名 - 数据库管理员堆栈交换 [ ^ ]
分配排名 - MySQL Cookbook [书籍] [ ^ ]
Depending on MySql database version ranking functions may not be available... See: MySQL :: MySQL 8.0 Reference Manual :: 12.21.1 Window Function Descriptions[^]
In that case, check this:
mysql - Get the rank of a user in a score table - Database Administrators Stack Exchange[^]
Assigning Ranks - MySQL Cookbook [Book][^]
这篇关于在mysql中排名功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!