mysql实现分析函数

上传人:206****923 文档编号:37509577 上传时间:2018-04-17 格式:DOCX 页数:2 大小:17.22KB
返回 下载 相关 举报
mysql实现分析函数_第1页
第1页 / 共2页
mysql实现分析函数_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《mysql实现分析函数》由会员分享,可在线阅读,更多相关《mysql实现分析函数(2页珍藏版)》请在金锄头文库上搜索。

1、MySQL 实现分析函数实现分析函数表,数据准备。表,数据准备。drop table test;create table test(name varchar(10),name1 varchar(10),count bigint);delete from test;insert into test values(1,a,2);insert into test values(1,b,1);insert into test values(1,c,4);insert into test values(1,d,5);insert into test values(1,e,7);insert into t

2、est values(1,f,8);insert into test values(2,g,9);insert into test values(2,h,0);insert into test values(2,i,21);insert into test values(2,j,3);insert into test values(2,k,4);insert into test values(2,l,56);insert into test values(3,m,67);insert into test values(3,n,89);insert into test values(3,o,12

3、);insert into test values(3,p,22);insert into test values(3,q,23);insert into test values(3,r,42);insert into test values(3,s,26);需求。需求。根据 name 字段分组,取出改组内的前 4 项,并且按照 count 字段进行降序排序,由于 mysql 没有oracle 中的分析函数,看上去很简单的需求,但是折腾了许久,还是没有实现,于是乎在网上收罗了一下 mysql 分析函数是怎么实现的 ,找到了 mysql 分析函数的解决办法,学习了一下,于是乎把同事的功能实现了;

4、实现。实现。select name, name1, count from (select b.name, b.name1, b.count,if(name = b.name, rank := rank + 1, rank := 1) as rank,name:=b.namefrom (select name, name1, count from test order by name asc, count desc) b,(select rownum := 0, name := null, rank := 0) a) result where rank 行为 1条件为假,执行 行为 22.:= MySQL 中赋值符号

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号