Subject | Re: [firebird-support] Query and problem with nulls |
---|---|
Author | Luigi Siciliano |
Post date | 2018-01-04T16:24:30Z |
Hallo,
Not works because in DT there is not rows between 01/01/2018 and 31/12/2018.
Try use explicit JOIN here:
...
FROM
DOC_CORPO DC, DOC_TESTA DT
But I solved:
I have another table in database that contains foreign keys for dt.deposito_id.
I modified the query like this, and now works ok:
SELECT
DEPOSITO_ID,
RIPORTO,
CARICO,
SCARICO,
RIPORTO + ESISTENZA AS ESISTENZA,
IMPEGNATI,
ORDINATI
FROM
(
SELECT
D.ID AS DEPOSITO_ID,
(SELECT
SUM(DC2.CARICO - DC2.SCARICO)
FROM
DOC_CORPO DC2,
DOC_TESTA DT2
WHERE
DC2.DOC_TESTA_ID = DT2.ID
AND DC2.ARTICOLO_ID = :ID
AND DT2.DATA < :DaData
) AS RIPORTO,
SUM(DC.CARICO) as Carico,
SUM(DC.SCARICO) as Scarico,
SUM(DC.CARICO - DC.SCARICO) as ESISTENZA,
SUM(DC.IMPEGNATI) as Impegnati,
SUM(DC.ORDINATI) as Ordinati
FROM
DEPOSITI D
LEFT JOIN DOC_TESTA DT ON D.ID = DT.DEPOSITO_ID,
DOC_CORPO DC
WHERE
DC.ARTICOLO_ID = :ID
AND DT.DATA >= :DaData
AND DT.DATA <= :AData
GROUP BY
D.ID
)
Thanks.
--
Luigi Siciliano --------------------------