Monday, 29 February 2016

[firebird-support] SUM(DC.I) / SUM(DC.Q) vs SUM(DC.I / DC.Q) why result is different?

Hallo,
I have, in DC table, two rows with same data:
A_ID I Q
1 370 1
2 370 1

with this query:

SELECT FIRST 1
DT.D as DCU,
SUM(DC.I) / SUM(DC.Q) AS CU,
(SELECT
SUM(DC.I) / SUM(Q)
FROM
DOC_C DC
WHERE
DC.C > 0.00
AND DC.A_ID = :ID
) AS CM
FROM
DOC_C DC, DOC_T DT
WHERE
DC.DOC_T_ID = DT.ID
AND DC.C > 0.00
AND DC.A_ID = :ID
GROUP BY
DT.D
ORDER BY
DT.D

I obtain correct result:
CU = 370
CM = 370

but with this query:

SELECT FIRST 1
DT.D as DCU,
SUM(DC.I / DC.Q) AS CU,
(SELECT
SUM(DC.I) / SUM(Q)
FROM
DOC_C DC
WHERE
DC.C > 0.00
AND DC.A_ID = :ID
) AS CM
FROM
DOC_C DC, DOC_T DT
WHERE
DC.DOC_T_ID = DT.ID
AND DC.C > 0.00
AND DC.A_ID = :ID
GROUP BY
DT.D
ORDER BY
DT.D


I obtain wrong result:
CU = 740
CM = 370


Why?

What is the difference from "SUM(DC.I) / SUM(DC.Q)"
and "SUM(DC.I / DC.Q)"

Thanks
--
Luigi Siciliano
--------------------------


------------------------------------

------------------------------------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://www.firebirdsql.org and click the Documentation item
on the main (top) menu. Try FAQ and other links from the left-side menu there.

Also search the knowledgebases at http://www.ibphoenix.com/resources/documents/

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/firebird-support/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/firebird-support/join
(Yahoo! ID required)

<*> To change settings via email:
firebird-support-digest@yahoogroups.com
firebird-support-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/

No comments:

Post a Comment