6

これは私の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......

助けていただければ幸いです。

4

2 に答える 2

6

フィールド順:

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')
于 2012-06-19T19:00:07.743 に答える
1

inner joinの代わりにフィルタリングを使用できます。これにより、句where ... inで参照できる順序を指定できます。order by

select  wc.name
,       wc.description 
from    wp_widget_custom wc
join    (
        select 1 as nr, 'hemel-hempstead' as name
        union all select 2, 'maidenhead'
        union all select 3, 'guildford'
        union all select 4, 'bromley'
        union all select 5, 'east-london'
        union all select 6, 'hertfordshire'
        union all select 7, 'billericay'
        union all select 8, 'surrey'
        ) as filter
on      filter.name = wc.name
order by
        filter.nr
于 2012-06-19T19:00:18.553 に答える