0
I have a table with the following result:
------------------
|seq | ID |
------------------
| 1 | 12345 |
| 2 | 12345 |
| 3 | 12345 |
| 4 | 12345 |
| 8 | 12345 |
| 9 | 54321 |
| 10 | 54321 |
| 11 | 54321 |
| 12 | 54321 |
| 13 | 54321 |
| 14 | 12345 |
| 15 | 12345 |
------------------
And right now I’m using the following query:
SELECT min(cardinals.seq) as start, max(cardinals.seq) as stop, r.PART_NUMBER --tao em uso no codigo
FROM (
SELECT A.N + 5*(B.N + 5*(C.N + 5*(D.N + 5*(E.N + 5*(F.N))))) AS seq
FROM (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) AS A
JOIN (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) AS B
JOIN (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) AS C
JOIN (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) AS D
JOIN (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) AS E
JOIN (SELECT 0 AS N UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) AS F
) cardinals
JOIN (
SELECT PART_NUMBER, MIN(SERIAL_NUMBER) as minSeq, MAX(SERIAL_NUMBER) as maxSeq
FROM manifa6_import_manif
where wu_name='FT4WU9C7'
GROUP BY PART_NUMBER
) r ON cardinals.seq >= r.minSeq AND cardinals.seq <= r.maxSeq
LEFT JOIN manifa6_import_manif ON cardinals.seq = manifa6_import_manif.SERIAL_NUMBER AND r.PART_NUMBER = manifa6_import_manif.part_number
WHERE manifa6_import_manif.SERIAL_NUMBER IS NULL
The result of this query is NULL
And I need you to give me the following result:
-------------------------
|start | Stop | ID |
-------------------------
| 1 | 4 |12345 |
| 8 | 8 |54321 |
| 9 | 13 |54321 |
| 14 | 15 |12345 |
-------------------------
Can you help me? Thank you
thanks in advance for the reply.
– Gomez