Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize the function of Excel grouping sorting in MySQL

Shulou Source: shulou.com Published: 2022-05-31 21:39:41 10月03日 Update

This article will explain in detail how to achieve the Excel grouping and sorting function in MySQL. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

1. There is a data sheet tmp_provice_sales as follows: the table records the sales volume of cities in a commodity province, and now you need to extract the city data of TOP1 sales in each province.

2. Then enter the following code in the query box:

3. Click "run" to obtain the sales TOP1 data of each province. The running result is shown below:

The points to be noted are:

The sales of the original data source need to be sorted in descending order, order by provice, sales desc, and the data of the same province are arranged together, and the sales volume is arranged from large to small.

Then use the if function to add the serial number to the data

Extract the data ranked 1 in each group, that is, the demand data.

If you want to get top3 data, just modify the last sentence, having ranks

Tags: Data sales province grouping sorting function original code content city quantity article more knowledge article run good same middle row function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL OPPO Reno vpn Microsoft