Get the App
SLTechnology News&Howtos  ›  Database  › 

Specify an ID to find the upper and lower range

Shulou Source: shulou.com Published: 2022-06-01 06:35:53 11月18日 Update

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

Tags: Songs results three weeks complex but variables ideas needs plus one up and down range Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info MySQL Huawei macOS