R | C1 | C2 | C3 | C4 |
---|---|---|---|---|
R1 | 1 | one | B | 1 |
R2 | 1 | B | C | 2 |
R3 | 1 | C | D | 3 |
R4 | 2 | one | D | 1 |
R5 | 3 | one | D | 1 |
R6 | 3 | D | X | 2 |
I have a tablemy_table
in mySQL which contains the above row and column details. I need to get all values ofc1
where startingc2
value =A
and endingc3
value =D
.
The rows in the table are sorted by
R
, so thestart
c2value forc1=1
isA
, theend
c3value ofc1=1
isD
C1 |
---|
1 |
2 |
Forc1=1
there are 3 lines:
R | C1 | C2 | C3 | C4 |
---|---|---|---|---|
R1 | 1 | one | B | 1 |
R2 | 1 | B | C | 2 |
R3 | 1 | C | D | 3 |
You can see here that the firstC2
isA
and the lastC3
isD
This satisfies the condition, so the value of1
forC1
should be included in the output.
Forc1=2
there is 1 row:
R | C1 | C2 | C3 | C4 |
---|---|---|---|---|
R4 | 2 | one | D | 1 |
ItsC2
isA
andC3
isD
, so this should be included in the output as well.
Forc1=3
there are 2 rows:
R | C1 | C2 | C3 | C4 |
---|---|---|---|---|
R5 | 3 | one | D | 1 |
R6 | 3 | D | X | 2 |
The firstC2
isA
, and the lastC3
isX
This does not satisfy the condition, so theC1
value of3
shouldnotbe included in the output. < /p>
I only need the C1 value that satisfies the condition.
Assume that the input selection is ordered, and we consider that the grouped sets of
C1
values have the same order, starting with the first rowC2
and ending with the last rowC3
value, then we can construct this sequence for each value ofC1
: