| 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_tablein mySQL which contains the above row and column details. I need to get all values ofc1where startingc2value =Aand endingc3value =D.
The rows in the table are sorted by
R, so thestartc2value forc1=1isA, theendc3value ofc1=1isD
| C1 |
|---|
| 1 |
| 2 |
Forc1=1there 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 firstC2isAand the lastC3isD
This satisfies the condition, so the value of1forC1should be included in the output.
Forc1=2there is 1 row:
| R | C1 | C2 | C3 | C4 |
|---|---|---|---|---|
| R4 | 2 | one | D | 1 |
ItsC2isAandC3isD, so this should be included in the output as well.
Forc1=3there are 2 rows:
| R | C1 | C2 | C3 | C4 |
|---|---|---|---|---|
| R5 | 3 | one | D | 1 |
| R6 | 3 | D | X | 2 |
The firstC2isA, and the lastC3isX
This does not satisfy the condition, so theC1value of3shouldnotbe 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
C1values have the same order, starting with the first rowC2and ending with the last rowC3value, then we can construct this sequence for each value ofC1: