IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    MySQL:Limit + In子查询

    Adamhuan发表于 2017-05-25 07:46:20
    love 0

    在MySQL中,如果在In这样的子查询中加入Limit,你可能会遇到错误:

    mysql> SELECT table_schema,table_name,partition_name,tablespace_name,partition_ordinal_position,create_time,update_time,check_time,checksum FROM information_schema.partitions WHERE table_name='event_by_day' and partition_ordinal_position not in (select partition_ordinal_position FROM information_schema.partitions WHERE table_name='event_by_day' order by partition_ordinal_position desc limit 0,3);
    ERROR 1235 (42000): This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
    mysql>

    暂时,解决该问题的方法是,再增加一层子查询,如下:

    mysql> SELECT table_schema,table_name,partition_name,tablespace_name,partition_ordinal_position,create_time,update_time,check_time,checksum FROM information_schema.partitions WHERE table_name='event_by_day' and partition_ordinal_position not in (select m.partition_ordinal_position from (select partition_ordinal_position FROM information_schema.partitions WHERE table_name='event_by_day' order by partition_ordinal_position desc limit 0,3) as m);
    +--------------+--------------+----------------+-----------------+----------------------------+---------------------+-------------+------------+----------+
    | table_schema | table_name   | partition_name | tablespace_name | partition_ordinal_position | create_time         | update_time | check_time | checksum |
    +--------------+--------------+----------------+-----------------+----------------------------+---------------------+-------------+------------+----------+
    | theme        | event_by_day | e_date_p3      | NULL            |                          1 | 2017-05-24 23:05:59 | NULL        | NULL       |     NULL |
    | theme        | event_by_day | e_date_p4      | NULL            |                          2 | 2017-05-24 23:05:59 | NULL        | NULL       |     NULL |
    | theme        | event_by_day | e_date_p5      | NULL            |                          3 | 2017-05-24 23:05:59 | NULL        | NULL       |     NULL |
    | theme        | event_by_day | e_date_p6      | NULL            |                          4 | 2017-05-24 23:05:59 | NULL        | NULL       |     NULL |
    +--------------+--------------+----------------+-----------------+----------------------------+---------------------+-------------+------------+----------+
    4 rows in set (0.01 sec)
    
    mysql>

    ————————————————
    Done。



沪ICP备19023445号-2号
友情链接