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 the combinatorial cumulative sorting of fields in the table in SQL

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

Share

Shulou(Shulou.com)05/31 Report--

This article introduces how to achieve the combination and cumulative sorting of the fields in the table in SQL, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

The table is as follows:

1 10 12 2 2 9 8 2 3 12 8 3 1 9 9 3 1 12 0 3 2 5 18 2 2 20 0 2

All three fields are of type integer.

The requirements are as follows:

1. Search by index=2 2. Add all the same id together, and add the data together. 3. The final presented data should be sorted by in+out, from large to small.

To meet the above requirements: the SQL statement is designed as follows (assuming the table name is tab)

The code is as follows:

Select id,sum (in) as in,sum (out) as out from tab where index=2 group by id order by in + out desc

SQL on how to achieve the combination of fields in the table cumulative sorting is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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