我有以下查询:
SELECT ContractNr
, SequenceNr
, DurationBeginDate
, MIN(DurationBeginDate) OVER(PARTITION BY contractnr ORDER BY SEQUENCENR ASC) mindurdat
FROM AccountContract
WHERE ContractNr = 768
它返回以下结果:
ContractNr SequenceNr DurationBeginDate mindurdat
768 1 2008-03-08 00:00:00.0000000 2008-03-08 00:00:00.0000000
768 2 2008-06-08 00:00:00.0000000 2008-03-08 00:00:00.0000000
768 3 2008-09-08 00:00:00.0000000 2008-03-08 00:00:00.0000000
768 4 2008-12-08 00:00:00.0000000 2008-03-08 00:00:00.0000000
768 5 2007-06-08 00:00:00.0000000 2007-06-08 00:00:00.0000000
这不是我所期望的,我想要的mindurdat
字段DurationBeginDate
对应的是最低的SequenceNr
. 换句话说,对于所有这些记录,2008-03-08 00:00:00.0000000
我应该不明白为什么此示例中的最后一条记录保留原始DurationBeginDate
.
我知道我可以通过子查询获得正确的结果,但我想保持高效。