dbTalk Databases Forums  

AVG and SUM in subquery return wrong values

comp.databases.oracle comp.databases.oracle


Discuss AVG and SUM in subquery return wrong values in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
marc.daetwyler@bawag.com
 
Posts: n/a

Default AVG and SUM in subquery return wrong values - 03-15-2005 , 12:40 PM






Hi
I have the following query aggregating values over a column and
creating the sum over another column. Here everything works out fine.

SELECT c.timestamp, AVG(c.response) as response, SUM(c.quantity) as
quantity, c.trans
FROM
tbl_repo01_dest c
GROUP BY c.trans, c.timestamp

No I embed this query into another, more complex one to join the
results of the query with another table.

SELECT
b.timestamp,
b.response as response_cics,
a.response as response_arch,
b.quantity as quantity_cics,
a.quantity as quantity_arch,
b.trans as trans_cics,
a.trans as trans_arch
FROM
(tbl_repo06_dest) b ,
(SELECT c.timestamp, AVG(c.response) as response, SUM(c.quantity)
as quantity, c.trans from tbl_repo01_dest c group by c.trans,
c.timestamp) a
WHERE
a.trans=b.trans
AND
to_date(a.timestamp,'DD.MM.YYYY HH24:MI')=to_date
(b.timestamp,'DD.MM.YYYY HH24:MI')


The join works out fine and all the matching tuples are joined.
However, the columns constructed with the AVG and SUM Functions all
contain a value of 1 wich is not correct. I tried to use TO_NUMBER
both in the inner and outer SELECT without a result.

Any help is greatly appreciated
Bye
Marc

Reply With Quote
  #2  
Old   
GreyBeard
 
Posts: n/a

Default Re: AVG and SUM in subquery return wrong values - 03-15-2005 , 12:49 PM






On Tue, 15 Mar 2005 10:40:15 -0800, marc blathered into the void,
expecting a response:


http://groups.google.ca/groups?hl=en...66%40gmail.com


Reply With Quote
  #3  
Old   
Ed Prochak
 
Posts: n/a

Default Re: AVG and SUM in subquery return wrong values - 03-15-2005 , 01:06 PM



Are you sure the first query works????

Noticing that you group by a timestamp, I would not be surprised if
there was only one row with a given timestamp value. I do not think
Data types conversion is your problem.

Try to break the problem down into managable, TESTABLE pieces. (Hint:
go back to that first query and run it. I expect you'll be surprised at
the results.)

HTH,
Ed


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.