Skip site navigation (1) Skip section navigation (2)

sum multiple tables gives wrong answer?

From: "Michael Diener" <m(dot)diener(at)gomogi(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: sum multiple tables gives wrong answer?
Date: 2010-06-02 14:23:20
Message-ID: 001601cb025f$297d0940$7c771bc0$@diener@gomogi.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novice
Hi,

 

I'm new to the list and have the following situation happening "PostgreSQL
8.4.1, compiled by Visual C++ build 1400, 32-bit" running windows XP sp3

 

I have an SQL problem that I thought was easy to do but gives me always the
wrong answer.

 

2 Tables with a column called "flaeche" "double precision", in English
"area" and I want to sum up the values for flaeche in each table to give me
the total area for flaeche in each table.

 

Correct answer comes with this sql

select  sum(flaeche)/10000 as "greens HA"  from green;

 

result:

greenHA

1.25358085

 

Wrong Answer with this query

select 

 sum(green.flaeche)/10000 as "greens HA",

 sum (fairway.flaeche)/10000 as "fairway HA"

  from green, fairway;

 

result:

green HA                   fairway HA

48.8896531                 508.94143659

 

Fairway correct answer is  14.96886578 HA

Green correct answer is 1.25358085  HA

 

What is going on ??

 

Cheers

michael

 

Michael Diener

_________________________________________________________________

GOMOGI Mobile Geographics

LAKESIDE PARK B01

9020 KLAGENFURT

 

T: ++043 (0) 676 520 3600

E: m(dot)diener(at)gomogi(dot)com

W: www.gomogi.com

 

Responses

pgsql-novice by date

Next:From: Thom BrownDate: 2010-06-02 15:32:31
Subject: Re: [NOVICE] sum multiple tables gives wrong answer?
Previous:From: John GageDate: 2010-06-02 08:02:02
Subject: Re: Putting an aggregate value in an UPDATE statement...

pgsql-general by date

Next:From: Sam MasonDate: 2010-06-02 14:33:16
Subject: Re: Is it possible to make the order of output the same as the order of input parameters?
Previous:From: Merlin MoncureDate: 2010-06-02 14:10:18
Subject: Re: PosttgreSQL on AIX

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group