SQL怎么实现分组limit
本篇内容主要讲解“SQL怎么实现分组limit”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“SQL怎么实现分组limit”吧!
mysql> create table a (id int,fid int ,name varchar(10));
Query OK, 0 rows affected (0.10 sec)
mysql>insertintoavalue(1,1,'a');
QueryOK,1rowaffected(0.04sec)
mysql>insertintoavalue(2,1,'b');
QueryOK,1rowaffected(0.01sec)
mysql>insertintoavalue(3,1,'c');
QueryOK,1rowaffected(0.01sec)
mysql>insertintoavalue(4,2,'d');
QueryOK,1rowaffected(0.02sec)
mysql>insertintoavalue(5,2,'e');
QueryOK,1rowaffected(0.01sec)
mysql>insertintoavalue(6,2,'f');
QueryOK,1rowaffected(0.00sec)
mysql>select*froma
->;
+------+------+------+
|id|fid|name|
+------+------+------+
|1|1|a|
|2|1|b|
|3|1|c|
|4|2|d|
|5|2|e|
|6|2|f|
+------+------+------+
6rowsinset(0.00sec)
mysql> select * from a where 2>( select count(*) from a b where a.fid=b.fid and a.id<b.id )order by fid ;
+------+------+------+
| id | fid | name |
+------+------+------+
| 2 | 1 | b |
| 3 | 1 | c |
| 5 | 2 | e |
| 6 | 2 | f |
+------+------+------+
4 rows in set (0.00 sec)
mysql> select * from a where 2>( select count(*) from a b where a.fid=b.fid and a.id>b.id )order by fid ;
+------+------+------+
| id | fid | name |
+------+------+------+
| 1 | 1 | a |
| 2 | 1 | b |
| 4 | 2 | d |
| 5 | 2 | e |
+------+------+------+
4 rows in set (0.00 sec)
到此,相信大家对“SQL怎么实现分组limit”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。