For the same col3 value in mySQL, how to get all rows if col1 of one row is equal to one value and col2 of the same row or different row is equal to another value?
P粉588660399
P粉588660399 2023-09-06 12:23:13
0
1
421

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 byR, so thestartc2value forc1=1isA, theendc3value ofc1=1isD

I expected output

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.

P粉588660399
P粉588660399

reply all (1)
P粉690200856

Assume that the input selection is ordered, and we consider that the grouped sets ofC1values have the same order, starting with the first rowC2and ending with the last rowC3value, then we can construct this sequence for each value ofC1:

C1 MinimumR C2 MaximumR C3
1 R1 one R3 D
2 R4 one R4 D
3 R5 one R6 X
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!