データベースから、連続する日付の差が最大になるように、日付ごとに 2 つの連続するレコードを選択したいと考えています。
机がある
お名前 日付 abc 1242 紀元前1246年 BSD 1247 bse 1249
クエリの結果は次のようになります。
abc 1242 紀元前1246年
私のクエリは次のとおりです。
select t1.name, t2.name, max(t2.date - t1.date)
from temp t1
join temp t2 on t1.date < t2.date
where
not exists (
select t3.date from temp t3 where t3.date > t1.date and t3.date < t2.date
)
これが最善の解決策ですか?
前もって感謝します