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> insert into a value (1,1,'a');
Query OK, 1 row affected (0.04 sec)
mysql> insert into a value (2,1,'b');
Query OK, 1 row affected (0.01 sec)
mysql> insert into a value (3,1,'c');
Query OK, 1 row affected (0.01 sec)
mysql> insert into a value (4,2,'d');
Query OK, 1 row affected (0.02 sec)
mysql> insert into a value (5,2,'e');
Query OK, 1 row affected (0.01 sec)
mysql> insert into a value (6,2,'f');
Query OK, 1 row affected (0.00 sec)
mysql> select * from a
-> ;
+------+------+------+
| id | fid | name |
+------+------+------+
| 1 | 1 | a |
| 2 | 1 | b |
| 3 | 1 | c |
| 4 | 2 | d |
| 5 | 2 | e |
| 6 | 2 | f |
+------+------+------+
6 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 |
+------+------+------+
| 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”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341