mssql 求每行相邻值相同的范围区间 sql语句


   
  CREATE TABLE #tbTest  (a bigint ,b varchar(100))
  
INSERT #tbTest
SELECT 1,'sa' UNION all
SELECT 3,'sa' UNION ALL
SELECT 6,'sa' UNION ALL
SELECT 9,'b' UNION ALL
SELECT 13,'c' UNION ALL
SELECT 16,'c' UNION ALL
SELECT 19,'sa'

SELECT * FROM #tbTest

1 sa
3 sa
6 sa
9 b
13 c
16 c
19 sa

已经 排好序的了

结果:

   
  1-6  sa
  
9-9 b
13-16 c
19-19 sa

mssql

siemen 10 years, 7 months ago

Your Answer