From: | Robins Tharakan <robins(dot)tharakan(at)comodo(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Cc: | Tarlika Elisabeth Schmitz <postgresql6(at)numerixtechnology(dot)de> |
Subject: | Re: GROUP and ORDER BY |
Date: | 2011-11-08 04:27:08 |
Message-ID: | 4EB8AF9C.7060305@comodo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Unless I overlooked something here, does this work ?
SELECT no, name, MAX(similarity(name, 'Tooneyvara')) AS sim
FROM vtown
WHERE similarity(name, 'Tooneyvara') > 0.4
GROUP BY no, name
ORDER BY sim DESC
--
Robins Tharakan
On 11/08/2011 02:50 AM, Tarlika Elisabeth Schmitz wrote:
> Hello,
>
> I would like to GROUP the result by one column and ORDER it by another:
>
> SELECT
> no, name, similarity(name, 'Tooneyvara') AS s
> FROM vtown
> WHERE similarity(name, 'Tooneyvara')> 0.4
> ORDER BY s DESC
>
> Result:
>
> 1787 "Toomyvara" 0.5
> 1787 "Toomevara" 0.4
> 1188 "Toonybara" 0.4
>
>
> Desired result:
>
> 1787 "Toomyvara" 0.5
> 1188 "Toonybara" 0.4
>
> Gets rid of the duplicate "no" keeping the spelling with the greater
> similarity and presents the remaining result ordered by similarity.
>
>
> My solution:
>
> SELECT * FROM
> (
> SELECT DISTINCT ON (no)
> no, name,
> similarity(name, 'Tooneyvara') AS sim
> FROM vtown
> WHERE similarity(name, 'Tooneyvara')> 0.4
> ORDER BY no, sim DESC
> ) AS x
> ORDER BY sim
>
>
> Is that the best way to achieve this result?
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2011-11-08 05:16:28 | Re: the use of $$string$$ |
Previous Message | Tarlika Elisabeth Schmitz | 2011-11-07 21:20:31 | GROUP and ORDER BY |