本篇内容主要讲解“sql怎么实现分组limit”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“SQL怎么实现分组limit”吧!Mysql> create
本篇内容主要讲解“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”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
--结束END--
本文标题: SQL怎么实现分组limit
本文链接: https://lsjlt.com/news/59040.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0