Subject | RE: [firebird-support] Re: group by ?? |
---|---|
Author | Leyne, Sean |
Post date | 2008-06-09T20:59:20Z |
Dani,
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
> What I have to do is so simple; just to read the last record added toin
> 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
> format YYYYMMDDHHMM (YEAR-MONTH-DAY-OUR-MINUTES).big,
>
> I have to read the last full record of each group. The table is so
> 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