---
# System prepended metadata

title: 626. Exchange Seats

---

# [626. Exchange Seats](https://leetcode.com/problems/exchange-seats/description/?envType=study-plan-v2&envId=top-sql-50)
![image](https://hackmd.io/_uploads/rkTOVF-06.png)
![image](https://hackmd.io/_uploads/rJmYEtW0a.png)
這一次我們要將id奇變偶
所以用到了新函數
ROW_NUMBER()
查詢出來的每一列資料加上一個序號


```SQL
SELECT ROW_NUMBER() OVER() id, student
FROM seat
ORDER BY IF(MOD(id, 2) = 0, id-1, id+1)

```