Subject | Re: [firebird-support] Re: Sum results of a subquery? |
---|---|
Author | Kjell Rilbe |
Post date | 2005-02-15T13:18:49Z |
Svein Erling Tysvær wrote:
doesn't matter. The application loop seems to be working nicely right
now, but I'll keep your method in mind as an alternative, just in case.
Thanks,
Kjell
--
--------------------------------------
Kjell Rilbe
Adressmarknaden AM AB
E-post: kjell.rilbe@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64
> In your case, there is actually a 3. only involving SQL as well:Interesting suggestion. :-) Using count > 2 is not of interest so that
>
> select count(*)
> from "TheTable" T1
> join "TheTable" T2
> on T2."Category" = T1."Category" and T2.PK > T1.PK
> where not exists(select * from "TheTable" T3
> where T3."Category" = T1."Category" and T3.PK < T1.PK)
>
> PK is PrimaryKey or anything unique within "TheTable". The NOT EXISTS
> will ascertain that T1 only contains the first record for each
> category, whereas T2.PK > T1.PK will take make T2 contain all records
> but the first for each category.
>
> Though I guess this become messy once you use count>2 rather than >1
> (it should still be possible) and I have no idea about performance.
doesn't matter. The application loop seems to be working nicely right
now, but I'll keep your method in mind as an alternative, just in case.
Thanks,
Kjell
--
--------------------------------------
Kjell Rilbe
Adressmarknaden AM AB
E-post: kjell.rilbe@...
Telefon: 08-761 06 55
Mobil: 0733-44 24 64