Мой подзапрос T- SQL, возвращающий более 1 строки:
WITH ReportView AS
(
SELECT
PMA.AssetName, ReleaseDt, ExpiresDt, TicketNumber, ChangeDt,
ChangeReasonCd,
ROW_NUMBER() OVER (PARTITION BY PMA.AssetName, ReleaseDt, ExpiresDt, TicketNumber, ChangeReasonCd
ORDER BY ChangeDt ASC) AS ROW_NUM
FROM
pmm.pmmreleaserequest PRR WITH (nolock)
LEFT JOIN
pmm.PmmManagedAccount AS PMA WITH (nolock) ON PRR.ManagedAccountID = PMA.ManagedAccountID
LEFT JOIN
dbo.ManagedEntity AS ME WITH (nolock) ON PRR.ManagedSystemID = ME.ManagedEntityID
LEFT JOIN
dbo.Asset AS AST WITH (nolock) ON ME.AssetID = AST.AssetID
LEFT JOIN
pmm.PmmLogChange AS PLC WITH (nolock) ON PRR.ManagedAccountID = PLC.ManagedAccountID
AND PRR.ExpiresDt < PLC.ChangeDt
)
SELECT *
FROM ReportView
WHERE ROW_NUM = 1
Как сравнить текущую строку ChangeDt со следующей строкой ReleaseDt. Пример ChangeDt (текущая строка)