Re: Can any_value be used like first_value in an aggregate?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Can any_value be used like first_value in an aggregate?
Date: 2024-06-27 13:06:29
Message-ID: 20240627130629.GA1433@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jun 26, 2024 at 09:50:59 +0200,
Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
>On Tue, 2024-06-25 at 14:11 -0500, Bruno Wolff III wrote:
>> The actual
>> use case is a set of tripplets returned from a query, where I want on
>> row for each distinct value in the first column, paired with the value
>> in the second column, for which the third column is the largest. The
>> second and third columns are effectively dependent on each other, so there
>> won't be any ambiguity.
>
>Try
>
> SELECT DISTINCT ON (first_column)
> first_column,
> second_column,
> third_column
> FROM the_table
> ORDER BY first_column, third_column DESC;

That approach worked for that part of the query. Thanks.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message agharta82@gmail.com 2024-06-27 15:20:21 A way to optimize sql about the last temporary-related row
Previous Message Michael Paquier 2024-06-27 06:43:11 Re: --frokbackend process