Re: Best Fit SQL query statement

Поиск
Список
Период
Сортировка
От hubert depesz lubaczewski
Тема Re: Best Fit SQL query statement
Дата
Msg-id 20070810075949.GA31829@depesz.com
обсуждение исходный текст
Ответ на Best Fit SQL query statement  (Kiran <kumar.m.kiran@gmail.com>)
Ответы Re: Best Fit SQL query statement  ("Fernando Hevia" <fhevia@ip-tel.com.ar>)
Список pgsql-sql
On Mon, Aug 06, 2007 at 01:57:07AM -0700, Kiran wrote:
> Could anyone  help me in writing Best Fit SQL statement.
> Suppose we have table t1 with coloumn t1 (text) with following rows.
> 98456
> 98457
> 9845
> 9846
> 984
> 985
> 98
> 99
> and if I query on 98456 the result must be 98456,
> However if I query on 98455 the result must be 9845
> and If I query 9849 the result must be 984

select t1.t1 from t1 where '98456' like t1.t1||'%' order by length(t1.t1) desc limit 1;

should be ok.

depesz

-- 
quicksil1er: "postgres is excellent, but like any DB it requires a
highly paid DBA.  here's my CV!" :)
http://www.depesz.com/ - blog dla ciebie (i moje CV)


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

Предыдущее
От: "Christian Kindler"
Дата:
Сообщение: Re: Returnd Refcurser ( not fetchable
Следующее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: Using function like where clause