我正在使用以下内容返回基于“服务器”的最新唯一记录列表
select server, fail, date, time
from (
select server, fail, date, time,
rank() over (partition by server order by date desc, time desc) as rank
from querytimes
) dt
where dt.rank <= 1;
它可以工作,但是速度很慢。
时间:21470.742 毫秒
输出示例,
server | fail | date | time
-------------------+------+------------+----------
serv1.test.com | No | 2013-02-21 | 10:25:03
serv2.test.com | No | 2013-02-21 | 10:25:03
serv3.test.com | No | 2013-02-21 | 10:25:03
serv4.test.com | No | 2013-02-21 | 10:25:03
serv5.test.com | No | 2013-02-21 | 10:25:03
serv6.test.com | No | 2013-02-21 | 10:25:03
serv7.test.com | No | 2013-02-21 | 10:25:02
serv8.test.com | No | 2013-02-21 | 10:25:01
serv9.test.com | No | 2013-02-21 | 10:25:01
serv10.test.com | No | 2013-02-21 | 10:25:02
serv11.test.com | No | 2013-02-21 | 10:25:02
serv12.test.com | No | 2013-02-21 | 10:25:02
serv13.test.com | No | 2013-02-21 | 10:25:01
serv14.test.com | No | 2013-02-21 | 10:25:01
有没有更有效的方法来做这种类型的查询?