Jump to content

select between 2 rows of each group


T0A

Recommended Posts

The Database that I'm using

I got it but I don't know how to match them together:

return the MAX-n1 & MAX-n2

SELECT
    MAX(`VID`)-3 AS max1,
    MAX(`VID`)-2 AS max2
FROM `tests`
GROUP BY `SID`

return the value of the rows:
 

SELECT *

FROM `tests`

WHERE `VID`>='max1' AND `VID`<='max2'

ORDER BY `SID` ASC, `VID` ASC

the results should be like this :
 

Quote

 

Group:1

test - 3

test - 4

 

Group:2

test - 283

test - 284

 

Group:3

test - 197

test - 198

 

Group:4

test - 173

test - 174

 

Group:5

test - 117

test - 118

 

Group:6

test - 162

test - 163

 

Group:7

test - 203

test - 204

 

Group:8

test - 72

test - 73

 

Group:9

test - 126

test - 127

 

Group:10

test - 106

test - 107

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.