我有一个表active
和数据表如下.. 样本数据获得对未来最近的记录日期为每个不同的PID
id pid chq_date
-------------------------
1 6 2013-07-07
2 4 2013-10-06
3 4 2013-07-06
4 5 2013-01-06
5 13 2013-09-16
6 33 2013-09-08
7 4 2013-02-06
8 13 2013-01-06
9 7 2013-07-06
10 4 2013-08-02
我需要得到未来最近的日期记录为每个不同从样本数据 PID所需的输出是
id pid chq_date
-------------------------
1 6 2013-07-07
3 4 2013-07-06
5 13 2013-09-16
6 33 2013-09-08
9 7 2013-07-06
我曾尝试不同的查询,但没有得到期望的结果。这似乎是最接近我的查询是
select * from active where chq_date>=sysdate and chq_date in (select
min(chq_date) from active where pid in (select distinct pid from active))
但PID 4似乎有2行..它是如何不同 – 2013-04-24 09:05:22
敏(未来)日期aginst 4是2013年7月6日 – Sami 2013-04-24 09:10:24
因此,改变你想要的输出 – sashkello 2013-04-24 09:11:52