MySQL: Mengisih nombor pendua secara menaik
P粉763748806
2023-07-25 12:41:47
<p>我有一个表格,看起来像这样:</p>
<table class="s-table">
<kepala>
<tr>
<th>id</th>
<th>nilai</th>
</tr>
</kepala>
<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>我想要在某种循环中按照这种方式对它们进行递增排序。</p>
<table class="s-table">
<kepala>
<tr>
<th>id</th>
<th>nilai</th>
</tr>
</kepala>
<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>我相信这可以很容易地用PHP完成,但是我想看看是否可以使用SQL来实王<p>
Gunakan fungsi tetingkap ROW_NUMBER() dalam klausa ORDER BY:
Anda boleh lihat ini demo.