这是我的SQL查询:

select name,description
from wp_widget_custom
where name in ('hemel-hempstead','maidenhead',
  'guildford','bromley','east-london','hertfordshire','billericay','surrey')

我得到的结果是这样的:
name            description
hemel-hempstead Loreum ipsim
east-london     Loreum ipsim
bromley         Loreum ipsim BROMLEY
billericay      Loreum ipsim
maidenhead      Loreum ipsim maidenhead
hertfordshire   Loreum ipsim HERTFORDSHIRE
guildford       loreum ipsum Guildford
surrey          loreum ipsum surrey

我希望按查询中传递结果的方式排列结果:
hemel-hempstead ,maidenhead',guildford,bromley,east-london......

谢谢你的帮助。

最佳答案

按字段排序:

select name, description
from wp_widget_custom
where name in ('hemel-hempstead','maidenhead','guildford','bromley','east-london','hertfordshire','billericay','surrey')
order by field(name, 'hemel-hempstead','maidenhead','guildford','bromley','east-london','hertfordshire','billericay','surrey')

07-27 19:50