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) THEN 0 ELSE 1 END, CASE WHEN id NOT IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213981,53213982) THEN phone END ASC, CASE WHEN id NOT IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213981,53213982) THEN created_at END DESC修改sql让排序值为0的字段按照phone正序排序,其他的字段不变
时间: 2023-09-10 19:13:41 浏览: 117
EMM2017_Sph_Windows.zip_amma3_emm2017_地磁_地磁场_地磁坐标
5星 · 资源好评率100%
可以将第一个 `CASE` 表达式中的 `0` 修改为 `phone`,并将第二个 `CASE` 表达式中的 `phone` 修改为 `created_at`,如下所示:
```
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) THEN phone
ELSE 1
END,
CASE
WHEN id NOT IN (53213970,53213971,53213972,53213973,53213974,53213975,53213976,53213977,53213978,53213979,53213980,53213981,53213982) THEN created_at
END DESC;
```
这样就可以让排序值为0的字段按照phone正序排序,其他的字段不变。
阅读全文