Does anyone know how to get the maximum sequence count from each column in a table. For example if have table A which has the following data
id | n1 | n2 | n3 | n4 | n5 | n6 | n7 | n8 | n9 | n10| Max | Sets
----------------------------------------------------------------
1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 10 | 1 |
2 | 1 | 3 | 4 | 5 | 6 | 8 | 14 | 15 | 16 | 25 | 4 | 2 |
3 | 4 | 8 | 9 | 15 | 18 | 19 | 55 | 64 | 65 | 98 | 2 | 3 |
4 | 41 | 55 | 66 | 67 | 68 | 69 | 74 | 82 | 131| 132| 4 | 2 |
As you can see from the table above I need to get the maximum contiguous count of numbers from a row, in the above example I have added the column 'Max' & 'Sets' to show the required outcome.
In the first row there are 10 contiguous numbers (1 through 10) and only 1 set/group of continguous numbers, in the second there are only 4 (3,4,5,6) and 2 sets of continguous numbers (3 to 6 and 14 to 16).
I've been trying to figure this out for quite sometime but can't understand the query required (i.e. join or a straight select and if statements). I can do this in other languages but would rather prefer to have MySQL complete this calculation.
FOR i <= count(column)
IF count > sequence
THEN sequence = count
ELSE count ++
NEXT i
SQL Fiddle Contains my table and data and I am trying to make required query