On Wed, Sep 02, 2015 at 07:14:40PM -0400, Tom Smith wrote:
> Hi:
>
> I need to get the first and last tow in one sql like below
>
> select first(col1), last(col1) from table order by col1
Have you tried the window functions [1] last_value and first_value?
You could use something like:
SELECT
Hi:
The window function works for me (with adding limit 1 in the end to output
only one row
needed instead of many duplicate rows).
thanks very much.
On Thu, Sep 3, 2015 at 6:51 AM, Dickson S. Guedes
wrote:
> On Wed, Sep 02, 2015 at 07:14:40PM -0400, Tom Smith wrote:
>
Tom Smith schrieb am 03.09.2015 um 14:11:
>>
>> SELECT first_value(col1) over (order by col1),
>>last_value(col1) over (order by col1)
>> FROM table;
>>
> The window function works for me (with adding limit 1 in the end to output
> only one row
> needed instead of many
On 09/02/2015 05:14 PM, Tom Smith wrote:
Hi:
I need to get the first and last tow in one sql like below
select first(col1), last(col1) from table order by col1
I saw some posting in wiki with a custom function (or C extention)
to do this. Is it widely used and reliable?
On 09/02/2015 05:14 PM, Tom Smith wrote:
Hi:
I need to get the first and last tow in one sql like below
select first(col1), last(col1) from table order by col1
I saw some posting in wiki with a custom function (or C extention)
to do this. Is it widely used and reliable?
Try this:
SELECT
(SELECT
FROM
ORDER BY offset 0 LIMIT 1) ,
(SELECT
FROM
ORDER BY OFFSET (SELECT COUNT(*) ) LIMIT 1)
FROM LIMIT 1;
On Wed, Sep 2, 2015 at 7:27 PM, Rob Sargent wrote:
> On 09/02/2015 05:14 PM, Tom Smith wrote:
>
> Hi:
>
>
Thanks for suggestion. I could use two separate sqls, but I am looking to
get it in a single sql.
I just compiled and installed (under postgres id) first_last_agg C
extension.
http://pgxn.org/dist/first_last_agg/
it WORKED under postgres user with sample
select first(column1), last(column1) from
Hi:
I need to get the first and last tow in one sql like below
select first(col1), last(col1) from table order by col1
I saw some posting in wiki with a custom function (or C extention)
to do this. Is it widely used and reliable?
https://wiki.postgresql.org/wiki/First/last_(aggregate)
I am