代码之家  ›  专栏  ›  技术社区  ›  Gerald Ferreira

Mysql高级语句

  •  0
  • Gerald Ferreira  · 技术社区  · 17 年前

    以下是查询:

    SELECT *
    FROM dbcasino_db22.tb_content
    WHERE content_real_folder = 'foldername/' AND content_no < 5099
    

    选择* 来自dbcasino_db22.tb_content 其中content_real_folder='foldername/'并且content_no<5099具有最大值(内容_否)

    3 回复  |  直到 13 年前
        1
  •  3
  •   Jason    17 年前

    这应该能解决这个问题。ORDER命令告诉最大结果在顶部,LIMIT 1告诉它您只想要第一个结果

    SELECT * FROM dbcasino_db22.tb_content
    WHERE content_real_folder = 'foldername/' AND content_no < 5099
    ORDER BY content_no DESC
    LIMIT 1
    
        2
  •  0
  •   Joe Phillips    17 年前

    我认为最简单的解决方案是按content_no降序排序,然后将响应限制为1。

        3
  •  0
  •   pfote    17 年前

    SELECT * FROM dbcasino_db22.tb_content WHERE content_real_folder = 'foldername/' AND content_no < 5099 order by content_no desc limit 1