Hello!
I have a table with fields
TaskLetter, TaskType_ID
A1 1
A2 1
A3 1
A4 1
B5 2
B6 2
B7 2
B8 2
B9 2
B10 3
B11 3
B12 3
B13 3
B14 1
B15 1
B16 1
I need to get
A1-A4 - 1
B5-B9 - 2
B10 - B13 - 3
B14 - B16 - 1
How can this be done? Thank you in advance

    1 answer 1

    SELECT startrange + ' - ' + endrange as rng, task_id FROM (select min(task_letter) as startrange, max(task_letter) as endrange, task_id FROM test group BY substring(task_letter, 1, 1), task_id) a ORDER BY cast(substring(startrange, 2, len(startrange) - 1) AS int) 
    • It does not issue a B14-B16 interval, the whole question is precisely this - if I have a TaskType_ID inconsistent, and "sits" with gaps, A1-A4, B14-B16, it does not give the correct interval. As a result, two intervals for TaskType_ID = 1 should be visible (in this particular case). - nicknames