I'm trying to get groups of consecutive values from a table. I've been trying to find an example about this but I haven't been able to use it in my case.
This is a small part of a table I have.
CardID CardSerial CardStateID AssignUserID Denomination
----------- --------------------------- ----------- ------------ -------------
2685680 214026002 3 81 10
2685681 214026003 3 81 10
2685682 214026004 3 81 10
2685683 214026005 3 81 10
2685684 214026006 3 81 10
2685778 214026100 3 81 10
2685779 214026101 3 81 10
2685780 214026102 3 81 10
2685781 214026103 3 81 10
2685782 214026104 3 81 10
2685878 214026200 3 81 10
2685879 214026201 3 81 10
2685880 214026202 3 81 10
2685881 214026203 3 81 10
2685882 214026204 3 81 10
2685883 214026205 3 81 10
2685884 214026206 3 81 10
The results that I'm expecting are:
min value max value cant Den
--------------- --------------- -------- ----
214026002 214026006 5 10
214026100 214026104 5 10
214026200 214026206 7 10
The hard part for me is to get a group value to make a query like
select min(cardSerial), max(cardSerial), count(*), Den
from Cards
group by Den, GROUPING_VALUE_GENERATED