ORDER records based on parameters in IN clause

Поиск
Список
Период
Сортировка
<div class="Section1"><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">I have a stmt where the outer-query is limited by the results of the inner query. I would like the
outerquery to return records in the same order as the values provided in the IN clause (returned form the inner query).
</span></font><pclass="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; 
font-family:Arial">The inner_query is returning id’s ordered by count(id) , i.e by most common
occurrence.</span></font><pclass="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt; 
font-family:Arial">In essence,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial">when I say </span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial">select * from table where id IN (2003,1342,799, 1450) </span></font><p class="MsoNormal"><font
face="Arial"size="2"><span style="font-size:10.0pt; 
font-family:Arial">I would like the records to be ordered as 2003, 1342, 799, 1450.  The outer query has no knowledge
ofthe count(id) that the inner_query is ordering by.</span></font><p class="MsoNormal"><font face="Arial"
size="2"><spanstyle="font-size:10.0pt; 
font-family:Arial"> </span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">Currently postgres returns it in this order (1450,1342,799,2003)</span></font><p
class="MsoNormal"><fontface="Arial" size="2"><span style="font-size:10.0pt; 
font-family:Arial">Any help would be appreciated.</span></font><p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size:10.0pt;
font-family:Arial">Thanks,</span></font><p class="MsoNormal"><font face="Arial" size="2"><span style="font-size:10.0pt;
font-family:Arial">R. Verghese</span></font></div>

В списке pgsql-sql по дате отправления:

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: pg_attribute.attlen -1 for varchar e pbchar fields
Следующее
От: bumby
Дата:
Сообщение: Help with query, stuck :(