推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
1989922yan
V2EX  ›  Python

django 查询数据库,获得某一个用户的 “排名”, 除了整个数据库排序,找出 下标, 有更好的方法的吗??

  •  
  •   1989922yan · Jul 16, 2014 · 5984 views
    This topic created in 4454 days ago, the information mentioned may be changed or developed.
    6 replies  •  2014-07-17 01:34:43 +08:00
    zoowii
        1
    zoowii  
       Jul 16, 2014   ❤️ 1
    以前看到过的方法, 按区间划分,更新用户的分数(或者其他什么的)时候,用户所在的排名区间可以算出来,每个区间有多少人也可以知道.然后只要求出用户在那个小区间是多少名就好了
    yueyoum
        2
    yueyoum  
       Jul 16, 2014   ❤️ 1
    排名应用 用 redis zset, 生活从此变得美好
    vicalloy
        3
    vicalloy  
       Jul 16, 2014   ❤️ 1
    这样?
    select count(*) from xxx where yy>'zz'
    1989922yan
        4
    1989922yan  
    OP
       Jul 16, 2014
    @yueyoum
    哈哈哈,赞一个,好的
    Zuckonit
        5
    Zuckonit  
       Jul 16, 2014
    @yueyoum +1, 典型的redis应用场景
    20150517
        6
    20150517  
       Jul 17, 2014 via Android
    为什么要整个数据重新排序?你数据应该原来就是按用户排名,你得到用户新排名只要一个b树查找就知道了,怎么可能full scan
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2623 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 07:48 · PVG 15:48 · LAX 00:48 · JFK 03:48
    ♥ Do have faith in what you're doing.