MySQL: Doppelte Zahlen aufsteigend sortieren
P粉763748806
P粉763748806 2023-07-25 12:41:47
0
1
522
<p>我有一个表格,看起来像这样:</p> <table class="s-table"> <thead> <tr> <th>id</th> <th>values</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>1</td> </tr> <tr> <td>2</td> <td>1</td> </tr> <tr> <td>3</td> <td>1</td> </tr> <tr> <td>4</td> <td>2</td> </tr> <tr> <td>5</td> <td>2</td> </tr> <tr> <td>6</td> <td>2</td> </tr> </tbody> </table> <p> <table class="s-table"> <thead> <tr> <th>id</th> <th>values</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>1</td> </tr> <tr> <td>4</td> <td>2</td> </tr> <tr> <td>2</td> <td>1</td> </tr> <tr> <td>5</td> <td>2</td> </tr> <tr> <td>3</td> <td>1</td> </tr> <tr> <td>6</td> <td>2</td> </tr> </tbody> </table> <p>
P粉763748806
P粉763748806

Antworte allen(1)
P粉501683874

在ORDER BY子句中使用ROW_NUMBER()窗口函数:

SELECT *
FROM tablename
ORDER BY ROW_NUMBER() OVER (PARTITION BY `values` ORDER BY id), 
         `values`;

可以看看这个 demo.

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage