zxzm.net
当前位置:首页 >> mysql 排名 >>

mysql 排名

先排序 再 用 group by 取 假设 table xxx select * from (select * from xxx order by time desc ) a group by type order by type

set @count=0;select @count=@count+1 as `名次` from table_name order by `分数` desc;

答: 试运行段: select * from( SELECT obj.id, obj.score, CASE WHEN @rowtotal = obj.score THEN @rownum WHEN @rowtotal := obj.score THEN @rownum :=@rownum + 1 WHEN @rowtotal = 0 THEN @rownum :=@rownum + 1 END AS rownum FROM ( SEL...

这个如果想要性能的话,就用下面的sql语句实现: select orderNo from (select (@rowNum:=@rowNum+1) orderNo , userid ,pid from TABLE,(Select (@rowNum :=0) ) b )t where t.userid=2694 然后php获得这条结果数组,取第一个元素即是排序 如果...

嵌套查询 SELECT id,uid,reg,abcc from (select id,uid,reg,abcc from testcx ORDER BY reg desc) as v GROUP BY uid ORDER BY reg desc

速度快是不可能了,我就随便按照你说的列点数据,只取前两名,你领会一下吧 建表及数据 create table sc(sno int,cno int,score);insert into sc values (1,1,100);insert into sc values (2,1,80);insert into sc values (3,1,25);insert into ...

select a.姓名,(@rowNum:=@rowNum+1) as 名次from 表名 a,(Select (@rowNum :=0) ) border by 积分 DESC,注册时间

SELECT B.NAME, B.SCORES, (SELECT COUNT(1) + 1 FROM 分数表 A WHERE A.SCORES > B.SCORES) PM FROM 分数表 B ORDER BY PM;

MYSQL的降序排列 今天查询时需要用到降序排列,老是出错,仔细检查SQL语法也没问题, 后来才知道,原来order by要放在limit的前面。或者说limit要放在最后。 www.2cto.com [sql] String sql = "select * from s_dayreport " + "where userId = "...

SELECT shubmit as uid,count(shubmit) as 次数 FROM `表1` group by shubmit order by 次数 desc create table 表二 SELECT shubmit as uid,count(shubmit) as 次数 FROM `表1` group by shubmit order by 次数 desc ;//用于复制前未创建新表du...

网站首页 | 网站地图
All rights reserved Powered by www.zxzm.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com