In MySQL, I'm performing the following query:
SELECT DISTINCT substring_index(gponport, '/', -1) AS ONU
FROM pon
WHERE he = '10.52.8.5'
AND gponport LIKE '16/1/%'
ORDER BY cast(ONU as unsigned)
Where the format of the gponport is (example): 16/1/5
The output of the query is something like:
+------+
| ONU |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
+------+
I need to retrieve the next onu available in the sequenze. In above example, the expected output is 11.
...but, if the sequence is broken, example:
+------+
| ONU |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
+------+
Then I need the query to return number 5 instead.
1value then you need this value to be returned, is it?sql-related question, but problems like this is much better handled (and controlled) in application layer, e.g. Go/PHP/Nodejs/whatever data programming/processing language you prefer.