【发布时间】:2018-08-04 06:54:04
【问题描述】:
Sybase DBMS
在我的玩家表中,我有 4 列:
- 播放器
- 得分
- post_dt
- add_dt
如果我想找到post_dt是最大值的玩家的分数,add_dt是那个post_dt和那个玩家的最大值,我该怎么做?我的以下查询需要很长时间才能运行,并且可能效率不高。
select player, score from tb t1
where post_dt in
(select max(add_dt)
from tb t2
where t1.player = t2.player and t2.post_dt in
(select max(post_dt)
from tb t2
where t1.player = t2.player))
表格
PLAYER SCORE POST_DT ADD_DT
001 15 2017-02-01 2017-01-15
001 26 2017-02-01 2017-01-17
001 31 2017-01-28 2017-01-10
002 4 2017-03-25 2017-02-25
002 14 2017-03-25 2017-02-13
002 27 2017-03-25 2017-03-05
003 31 2017-01-02 2016-12-25
003 4 2017-01-03 2016-12-25
查询的预期结果:
01, 26, 2017-02-01, 2017-01-17
02, 27, 2017-03-25, 2017-03-05
03, 4, 2017-01-03, 2016-12-25
【问题讨论】:
-
你的 dbms 是什么?
-
你能详细说明一下吗,最好是一些示例数据。很难理解您的要求。
-
哪个 Sybase RDBMS 产品(ASE?SQLAnywhere?IQ?Advantage?)和版本?除了Cetin的评论,请阅读How to create a Minimal, Complete and Verifiable example,然后回来更新你的问题
-
我用示例数据更新了我的帖子。