Subject RE: [firebird-support] Re: group by ??
Author Leyne, Sean
Dani,

> What I have to do is so simple; just to read the last record added to
> each group.
>
> Field PROC represent the group ID.
>
> Field MOVI represent a unique primary key for each record in MOVI.
>
> Field FECH represent the date/time of the imput as a string litereal
in
> format YYYYMMDDHHMM (YEAR-MONTH-DAY-OUR-MINUTES).
>
> I have to read the last full record of each group. The table is so
big,
> may be 50.000 or more groups and 30 or more records each group.

Still not sure I understand, but..

Try the following:

SELECT
M1."PROC"...
FROM "MOVI" M1
WHERE
NOT EXIST (
SELECT 1
FROM "MOVI" M2
WHERE
M2."PROC" = M1."PROC"
AND M2."FECH" > M1."FECH")
)

Create a compound index on PROC and FECH (in that order) and the
performance will be pretty good.


Sean