gpt4 book ai didi

php - 按where条件排序

转载 作者:行者123 更新时间:2023-11-29 01:08:58 25 4
gpt4 key购买 nike

我有以下查询:

select `state` from `table1` 
where `state` in ('NC','North Carolina','TN','Tennessee','CO','Colorado','NM','New Mexico','UT','Utah')
limit 200 offset 0

我需要按 state 排序的结果,因为它们出现在我的 where 子句中(即首先是 NC,然后是 TN,然后是 CO,依此类推)。

我该怎么做?我尝试使用 order by 但它没有给出这个结果。

最佳答案

你可以使用 ORDER BY FIELD

SELECT `state`
FROM `table1`
WHERE `state` IN ('NC','North Carolina','TN','Tennessee','CO','Colorado','NM','New Mexico','UT','Utah')
ORDER BY FIELD(`state`, 'NC','North Carolina','TN','Tennessee','CO','Colorado','NM','New Mexico','UT','Utah');

关于php - 按where条件排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13373862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com