Re: Simple SQL?

From: Goran Sliskovic <gsliskov_at_yahoo.com>
Date: Thu, 17 May 2001 23:21:55 +0200
Message-ID: <9e1fg8$fof$1_at_ss204.hinet.hr>


Jan Hidders <hidders_at_REMOVE.THIS.win.tue.nl> wrote in message news:9e1ajr$6or$1_at_news.tue.nl...
> Stefan Peschke wrote:
> > Hi,
> > is there a 'simple' SQL-statement for the following problem?
> >
> > I have 3 tables
> >
> > Tbl a
> > a
> > 1
> >
> > Tbl b
> > b1 b2
> > 1 1
> > 1 2
> >
> > Tbl c
> > c1 c2
> > 1 3
> > 1 4
> > 1 5
> >
> > [...]
> >
> > and I want
> > a sum(b) sum(c)
>
> Why did you not simply try the following?
>
> SELECT a, SUM(b2), SUM(c2)
> FROM tblA, tblB, tblC
> WHERE a = b1 AND a = c1
> GROUP BY a
>
> --
> Jan Hidders

It will return wrong result.
before group by result set is:

a b1 b2 c1 c2

1    1      1     1     3
1    1      1     1     4
1    1      1     1     5
1    2      1     1     3
1    2      1     1     4
1    2      1     1     5

So it will return 3xsum(b2) and 2xsum(c2).

Goran Received on Thu May 17 2001 - 23:21:55 CEST

Original text of this message