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 id IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213981,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) THEN phone ELSE NULL END ASC NULLS LAST;出现错了SQL 错误 [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULLS LAST LIMIT 0, 200' at line 11 Error position: line: 10
时间: 2023-09-18 22:09:24 浏览: 340
这段 SQL 语句中的问题在于 NULLS LAST 的位置不正确,因为在 MySQL 中并不支持这种写法。正确的写法应该是使用 DESC 关键字将排序顺序反转,将 NULL 值排在最后面。修改后的 SQL 语句如下:
```
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 id IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213981,53213982,53213983,53213984,53213985,53213986,53213987,53213988,53213989) THEN phone
ELSE NULL
END DESC;
```
通过上述修改,使用 DESC 关键字将第二个 CASE 表达式的排序顺序反转,并且去掉了 NULLS LAST,以保证整个语句的正确性。
阅读全文