Re: GROUP BY's on 3 tables in one SELECT?
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 19 Aug 2005 21:40:04 +0200
On Thu, 18 Aug 2005 16:12:02 -0700, Martin S. wrote:
(snip)
>Unfortunately, the tables were not created by me (I just want to extract
>something), so I can't include any CREATE TABLE statement.
Hi Martin,
The website I refered you to includes a description of how you can
easily create a script from your database. It also has a link to a
script that will generate INSERT statements from existing data.
The sample data you posted doesn't help much either, as their formatting
is off (at least in my news reader). There's a reason I asked you to
post the sample data as INSERT statements, you know...
Anyway, based on your narrative and my limited understanding of the
sample data you posted, the following might work:
SELECT T1.Person_ID, T1.Product_ID, MAX(Costs),
(SELECT SUM(T2b.Balancies)
FROM T3, T2 as T2b
WHERE T2b.PersonID = T1.PersonID
AND T2b.Product_ID = T3.Product_ID
AND T3.Product_Type = 'BB')
FROM T1, T2
WHERE (T1.Product_ID = T3.Product_ID) AND (T3.Product_Type='AA')
GROUP BY T1.Person_ID, T1.Product_ID
(untested)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
.
- Follow-Ups:
- Re: GROUP BY's on 3 tables in one SELECT?
- From: Martin S.
- Re: GROUP BY's on 3 tables in one SELECT?
- References:
- GROUP BY's on 3 tables in one SELECT?
- From: Martin S.
- Re: GROUP BY's on 3 tables in one SELECT?
- From: Hugo Kornelis
- Re: GROUP BY's on 3 tables in one SELECT?
- From: Martin S.
- GROUP BY's on 3 tables in one SELECT?
- Prev by Date: how to write query
- Next by Date: Re: how to write query
- Previous by thread: Re: GROUP BY's on 3 tables in one SELECT?
- Next by thread: Re: GROUP BY's on 3 tables in one SELECT?
- Index(es):
Relevant Pages
|
|