Re: Sum and count weird results

From: Michalis Kabrianis <mk(at)interzone(dot)gr>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Sum and count weird results
Date: 2004-08-11 17:04:57
Message-ID: 411A51B9.6000400@interzone.gr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Christoph Haller wrote:

> Michalis Kabrianis wrote:
>
>
>>Hi all,
>>I have these tables
>>
>>a (
>>id integer,
>>email varchar);
>>
>>b (
>>seat varchar,
>>transactionid varchar);
>>
>>c (
>>transactionid varchar,
>>totalprice numeric(8.2));
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 8: explain analyze is your friend
>
>
> And?
>

Oops, accidental "send button" hit.
I beleived it would never reach the list.
Sorry for that.

Here we go again:
Hi all,
I have these tables

a (
id integer,
email varchar);

b (
seat varchar,
transactionid varchar references c(varchar));

c (
transactionid varchar,
a_id integer references a(id),
totalprice numeric(8.2));

sample data :
table a
1,test1(at)test(dot)gr
2,test2(at)test(dot)gr

table b
1,123
2,123
3,123
4,125
5,125
6,127

table c
123,1,200
125,2,100
127,1,300

What I want is to count the seatnr located on table b, and sum the
totalprice located on table c, group by email located on table a.

I tried something like :
select sum(totalprice), count(seatnr), email from a,b,c where
c.transactionid=b.transactionid and c.a_id=a.id

I get correct seatnr count, but wrong (and I understand why) totalprice sum.
Any good ideas on how can that be accomplished in one query?

Ideal results :
SUM COUNT EMAIL
4 500 test1(at)test(dot)gr
2 100 test2(at)test(dot)gr

Thanks in advance

Michalis

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Haumer 2004-08-11 17:37:58 Re: Displaying two tables side by side
Previous Message Michael Kleiser 2004-08-11 16:44:57 Re: Displaying two tables side by side