V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
luckylion
V2EX  ›  MySQL

上一篇 下一篇排序

  •  
  •   luckylion · Apr 21, 2015 · 3459 views
    This topic created in 4029 days ago, the information mentioned may be changed or developed.

    table: article
    prefix: id(auto_increment),title(varchar),sort(int)

    查找当前文章的上一篇 下一篇怎样写,查询排序是 order by sort desc,id desc

    3 replies    2015-04-21 11:18:00 +08:00
    endoffight
        1
    endoffight  
       Apr 21, 2015 via Android   ❤️ 1
    数量不大的时候可以用临时表
    greyby
        2
    greyby  
       Apr 21, 2015   ❤️ 1
    子查询查询出ID,再关联 ```select * from article join (select id from article order by sort desc, id desc limit page_size offset page * page_size ) as ariticle_id using(id)```

    如果数据量很大且只需要上一页下一页翻可以参考 ```twitter timeline``` 使用的 ```[cursoring](https://dev.twitter.com/overview/api/cursoring)```
    SErHo
        3
    SErHo  
       Apr 21, 2015   ❤️ 1
    我是这样搞的,数据量大时不知道有问题没有:

    https://github.com/SerhoLiu/serholiu.com/blob/master/miniakio/libs/models.py#L101
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2271 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 01:22 · PVG 09:22 · LAX 18:22 · JFK 21:22
    ♥ Do have faith in what you're doing.