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-dig...@yahoogroups.com 
    firebird-support-fullfeatu...@yahoogroups.com

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

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

  • [fireb... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]
    • R... Dimitry Sibiryakov s...@ibphoenix.com [firebird-support]
      • ... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]
        • ... Fernando P. Nájera Cano y...@fernandonajera.com [firebird-support]
          • ... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]
          • ... Luigi Siciliano luigi...@tiscalinet.it [firebird-support]

Reply via email to