Moja logika zlyháva. Vysvetlí mi niekto, prečo je v druhom prípade polovičný čas? Veľmi ma to prekvapilo a mám silné nutkanie to všade opraviť/zmeniť. Keď sa tým už babrem, tak poriadne.
14 sek. Pôvodný dopyt. Agregačné funkcie sú v CTEWITH D AS
(SELECT D.FKOWNER_FLAT, SUM(D.DEPOSIT) AS DEPOSIT, SUM(D.PAY) AS PAID
FROM DEPOSITS D
WHERE D.FKFOCS = :FKFOCS AND D.DEPOSITPERIOD BETWEEN :FIRSTDATE AND :LASTDATE
GROUP BY D.FKOWNER_FLAT)
SELECT D.FKOWNER_FLAT, F.FLATNUMBER, O.FULLNAME, D.DEPOSIT, D.PAID, (D.PAID - D.DEPOSIT) AS DIFFERENCE
FROM FLATS F
INNER JOIN OWNER_FLAT OWF ON F.IDFLATS = OWF.FKFLAT
INNER JOIN D ON OWF.IDOWNER_FLAT = D.FKOWNER_FLAT
INNER JOIN OWNERS O ON OWF.FKOWNERS = O.IDOWNERS
6 sek. Agregačné funkcie sú ZA CTEWITH D AS
(SELECT D.FKOWNER_FLAT, D.DEPOSIT, D.PAY, D.PAY - D.DEPOSIT AS DIFFERENCE
FROM DEPOSITS D
WHERE D.FKFOCS = :FKFOCS AND D.DEPOSITPERIOD BETWEEN :FIRSTDATE AND :LASTDATE)
SELECT D.FKOWNER_FLAT, F.FLATNUMBER, O.FULLNAME, SUM(D.DEPOSIT) AS DEPOSIT, SUM(D.PAY) AS PAID,
SUM(D.DIFFERENCE) AS DIFFERENCE
FROM FLATS F
INNER JOIN OWNER_FLAT OWF ON F.IDFLATS = OWF.FKFLAT
INNER JOIN D ON OWF.IDOWNER_FLAT = D.FKOWNER_FLAT
INNER JOIN OWNERS O ON OWF.FKOWNERS = O.IDOWNERS
GROUP BY D.FKOWNER_FLAT, F.FLATNUMBER, O.FULLNAME
To je k tým dlhým dopytom. Bod B)