• ADADADADAD

    SQL怎么实现分组limit[ mysql数据库 ]

    mysql数据库 时间:2024-11-28 13:24:15

    作者:文/会员上传

    简介:

    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.04se

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    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.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: sql