我有一个这样的表格报告:
DBSCODE RPTDATE DBSSEQ
AAA 2012-01-31 1
AAA 2012-02-29 1
AAA 2012-02-29 2
AAA 2012-03-31 1
BBB 2012-01-31 1
BBB 2012-01-31 2
我想返回每个dbscode
for each的最大序列的详细信息rptdate
。但是,我现在正在运行的查询仅在 max dbsseq
> 1 时返回。
我正在执行:
select a.dbscode, a.rptdate, a.dbseq
from REPORTS as a
inner join
(select rptdate, max(dbsseq) as 'Last'
from REPORTS
group by rptdate) as b
on a.rprtdate = b.last
我的结果是:
DBSCODE, RPTDATE, DBSSEQ
AAA, 2012-02-29, 2
BBB, 2012-01-31, 2