2012-06-19 27 views
6

Bu benim SQL sorgusu geçerli:SQL SORGU Sonucu düzenlemesi sorunu

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

alıyorum sonuç bu formda geçerli:

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 

sonucun o geçirildi şekilde düzenlenmelidir istiyorum Sorgulama:

hemel-hempstead ,maidenhead',guildford,bromley,east-london...... 

Yardımı teşekkür ederiz, teşekkürler. alana göre

cevap

6

sırası:

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') 
+0

+1 Cevabıma :) daha üretmek için kolay – Andomar

+0

i biz –

+0

Güzel, öğrendik teşekkür gibi öğeleri sağlayabilir bilmiyordum muazzam yeni bir şey :) –

1

Bir filtreleme inner join yerine bir where ... in maddesini kullanabilir. Yani daha sonra order by fıkrada başvurabileceğiniz bir emir, belirlemenizi sağlar:

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 
İlgili konular