Guest User

129

a guest
Mar 27th, 2020
193
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WITH intLagLead
  2. AS
  3. (
  4. --Получаем границы диапазонов с привязкой к оригинальному ID
  5. SELECT Q_ID,
  6. CASE
  7. WHEN ISNULL(LAG(Q_ID) OVER (ORDER BY Q_ID), 0) =
  8. Q_ID - 1
  9. THEN NULL
  10. ELSE Q_ID - 1
  11. END AS intLead,
  12. CASE
  13. WHEN ISNULL(LEAD(Q_ID) OVER (ORDER BY Q_ID), Q_ID + 1) =
  14. Q_ID + 1
  15. THEN NULL
  16. ELSE Q_ID + 1
  17. END AS intLag
  18. FROM utQ
  19. )
  20. --Вытягваем интервалы.
  21. SELECT intLag, intLead
  22. FROM
  23. (
  24. --Собираем границы из двух - в одну строку.
  25. SELECT intLag, LEAD(intLead) OVER (ORDER BY Q_ID) AS intLead
  26. FROM intLagLead
  27. ) t
  28. WHERE intLag IS NOT NULL
RAW Paste Data