douyudouchao6779 2015-01-16 02:39
浏览 31

积分排名系统

Below is the code I have to retrieve the rank of a certain images, everything works perfectly fine. However, if two or more images has the same total points, I am getting duplicate rank results. My main goal is, if two or more images has tie total_points, rank them based on when these images were submitted. (old to recent order). How do I break the tie?

  • 写回答

2条回答 默认 最新

  • donglisi8644 2015-01-16 04:13
    关注

    You can use a variable to rank by total points descending and date ascending:

    set @rank = 0;
    select @rank := @rank + 1 as rank,
      photo_id,
      total_points,
      date
    from photo_list
    order by
      total_points desc,
      date asc
    

    SQL FIDDLE

    评论

报告相同问题?

悬赏问题

  • ¥15 java 在同一包下无法跨文件引入自己写的类,也无法导包过去
  • ¥15 求帮生成一个lattice diamond的许可证
  • ¥15 大一前端新生求教学解答
  • ¥15 如何制作一个可以查看“网游有序列的装备词条”的软件/插件
  • ¥15 CS2打5E与完美天梯匹配会与服务器断开连接(黑框没标明具体原因)
  • ¥15 利用cst反推材料电磁参数,推出想x,y,z方向的相对介电常数与磁导率
  • ¥15 求帮助!用赛灵思FPGA XC7A35T对一个频率50MHz的数字信号读取高低电平,只用HR bank普通单端io进行采样可以吗
  • ¥15 训练准确率100%,测试准确率只有50%
  • ¥15 grafana创建dashhabord提示no data sources of type Prometheus Alert
  • ¥15 python用arima时间序列法预测不出结果 急