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

How to realize row_number detailed explanation by mysql

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

Share

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

This article mainly introduces how to achieve row_number mysql detailed explanation, hope to give you some additional and updated knowledge, such as other issues need to know can continue to pay attention to my updated articles in the industry information.

Query test table by group_id select the first 100 sort_id

SELECT id AS 'original data ID', group_id AS ' grouping ID', sort_id AS 'sorting condition', num AS ' ranking 'FROM (SELECT @row_number := CASE WHEN @customer_no = group_id THEN @row_number + 1 ELSE 1 END AS num /* If same as group_id then rank plus 1, otherwise update to 1*/ ,@customer_no := group_id AS group_id /* Reload group_id*/ ,id , sort_id /* existing data */ FROM test,( SELECT @customer_no := 0,@row_number := 0) AS t ORDER BY group_id ,sort_id DESC ,id)a WHERE num

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