Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Specify an ID to find the upper and lower range

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report