Specify an ID to find the upper and lower range
It's not complicated.
Requirements:
Implementation ideas:
Given an ID, say 272944
If the ID in the table is greater than this value, the custom variable is incremented by one.
If the ID in the table is less than this value, subtract the ID in the table from this value.
0 if the ID in the table equals this value
SELECTa.ZpID,WHEN a.zpid - 272944 > 0 THEN @a:=@a + 1WHEN a.zpid - 272944
< 0 THEN a.zpid - 272944ELSE 0END AS rnFROMzp_audio_video a, (SELECT @a:=0) varsWHEREa.State = 1AND a.Labels LIKE '三周年站庆歌曲类%'ORDER BY a.Zpid 结果:
Last filter found results:
SELECT*FROM(SELECTa.ZpID,WHEN a.zpid - 272944 > 0 THEN @a:=@a + 1WHEN a. zpid-272944 < 0 THEN a. zpid-272944ELSE 0END AS rnFROMzp_audio_video a, (SELECT @a:=0) varsWHEREA.State = 1AND a.Labels LIKE 'SAN ZHOU YEAR STATIONING SINGLE CATEGORY %'ORDER BY a.Zpid) aTHERErn