SELECT * FROM emm_task.tbl_scm_passenger ORDER BY CASE WHEN id in (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213981,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) THEN 0 ELSE 1 END, flight_date asc SELECT * FROM emm_task.tbl_scm_passenger ORDER BY CASE WHEN id IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213981,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) then 0 ELSE 1 END, CASE WHEN phone IS NULL THEN 1 WHEN id IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) THEN 0 ELSE 2 END, phone ASC, CASE WHEN mobile IS NULL THEN 1 WHEN id IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) THEN 0 ELSE 3 END, mobile ASC这段代码中我想要排序的时候忽略mobile的空值排序,怎么修改
时间: 2023-09-13 20:03:52 浏览: 50
你可以将排序语句中的 `mobile ASC` 修改为 `CASE WHEN mobile IS NULL THEN 1 ELSE 0 END, mobile ASC`。这样可以先将空值的 mobile 排到最后,然后按照 mobile 的升序排列。修改后的代码如下:
```
SELECT *
FROM emm_task.tbl_scm_passenger
ORDER BY
CASE
WHEN id IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213981,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) THEN 0
ELSE 1
END,
CASE
WHEN phone IS NULL THEN 1
WHEN id IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) THEN 0
ELSE 2
END,
phone ASC,
CASE
WHEN mobile IS NULL THEN 1
WHEN id IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) THEN 0
ELSE 3
END,
CASE
WHEN mobile IS NULL THEN 1
ELSE 0
END,
mobile ASC
```
阅读全文