Re: ranked subqueries vs distinct question

Поиск
Список
Период
Сортировка
От David McNett
Тема Re: ranked subqueries vs distinct question
Дата
Msg-id 65212064-037C-4BC5-A7D7-79DCF9D5AF77@macnugget.org
обсуждение исходный текст
Ответ на ranked subqueries vs distinct question  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Ответы Re: ranked subqueries vs distinct question  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Список pgsql-general
On May 14, 2008, at 8:15 AM, Karsten Hilbert wrote:
> Effectively I want known-zip cities first, then
> fragment-matching cities but without those already in the
> known-zip list.
>
> Can anyone teach me how I need to do this in SQL ?

I think you've made things far more complicated than you need.  How
about an approach something along these lines...

SELECT
    name,zip,
    (SELECT zip = '04317') as zipmatch
FROM
  dem.urb
ORDER BY zipmatch DESC, name;

This will give you a nice resultset incorporating a boolean field ('t'
or 'f') reflecting whether or not the zip code matches.  Sorting DESC
on that "zipmatch" field will put the trues at the top of your result
set.

No unions, no messy intersection problems.  Much faster.  I hope that
applies to your situation.

-Nugget

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

Предыдущее
От: "mian wang"
Дата:
Сообщение: Re: ranked subqueries vs distinct question
Следующее
От: Karsten Hilbert
Дата:
Сообщение: Re: ranked subqueries vs distinct question