Subject | RE: [firebird-support] Group by question/problem |
---|---|
Author | Mercea Paul |
Post date | 2008-11-18T18:59:51Z |
> Hello All,[PM]
>
> I have following query:
>
> SELECT KD.DATA_DOST
> ,T.KOD
> ,(SELECT 1 FROM RDB$DATABASE WHERE
> EXISTS(SELECT KR.ODBIORCA_ID FROM MG_KONTRAKT_REZ KR WHERE
> KR.KONTENER_TOW_ID = KTOW.ID AND KR.ODBIORCA_ID = 'ODB')) REZ_CM
> ,COUNT (KTOW.KONTENER_ID)
>
> FROM MG_KONTRAKT_KONTENERY_TOW KTOW
> INNER JOIN MG_KONTRAKT_KONTENERY KT ON (KTOW.KONTENER_ID =
> KT.KONTENER_ID AND KT.STATUS >= 0)
> LEFT JOIN MG_INDEKS T ON (T.ID = KTOW.TOWAR_ID)
> LEFT JOIN MG_KONTRAKT_DOST KD ON (KTOW.DOST_ID = KD.DOST_ID)
> GROUP BY 1,2,3
>
> What should be the proper 'group by' part to get this query working - is
> it possible at all?
>
> I can provide additional info about tables structure when needed.
>
> TIA
> Marcin
Try
SELECT KD.DATA_DOST
,T.KOD
,COUNT (KTOW.KONTENER_ID)
FROM MG_KONTRAKT_KONTENERY_TOW KTOW
INNER JOIN MG_KONTRAKT_KONTENERY KT ON (KTOW.KONTENER_ID = KT.KONTENER_ID )
LEFT JOIN MG_INDEKS T ON (T.ID = KTOW.TOWAR_ID)
LEFT JOIN MG_KONTRAKT_DOST KD ON (KTOW.DOST_ID = KD.DOST_ID)
where KT.STATUS >= 0 and EXISTS(SELECT KR.ODBIORCA_ID FROM MG_KONTRAKT_REZ
KR WHERE
KR.KONTENER_TOW_ID = KTOW.ID AND KR.ODBIORCA_ID = 'ODB')
GROUP BY 1,2
[PM]
Regards,
Paul