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
| 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”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
新闻名称:SQL怎么实现分组limit
标题路径:http://cdiso.cn/article/ieejio.html