Re: GROUP BY's on 3 tables in one SELECT?
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 18 Aug 2005 22:55:38 +0200
On Thu, 18 Aug 2005 12:51:03 -0700, Martin S. <Martin
S.@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>Hi there, I'd like to ask you for help with following:
>
>having 3 tables:
>T1 (Person_ID, Product_ID, Costs)
>T2 (Person_ID, Product_ID, Balancies)
>T3 (Product_ID, Product_Type)
>
>I have simple GROUP BY query:
>SELECT T1.Person_ID, T1.Product_ID, MAX(Costs)
>FROM T1, T2
>WHERE (T1.Product_ID = T3.Product_ID) AND (T3.Product_Type='AA')
>GROUP BY T1.Person_ID, T1.Product_ID
>
>at the end of each row obtained from previous statement, I'd like to add
>sum of T2.Balancies for which (T1.Person_ID = T2.Person_ID) AND
>(T2.Product_ID = T3.Product_ID) AND (T3.Product_Type='BB')
>
>Is it possible to do it within one SELECT statement?
Hi Martin,
Probably - but your question has to be clarified first. I think that
there might be some typos in your query as well (e.g. the T2 after FROM
should be T3, right? And should the product type in the WHERE clause not
read BB instead of AA?)
To make sure that I'll understand the question you are asking and not
something else, I ask you to post details about your tables AS CREATE
TABLE STATEMENTS (and please include all constraints and roperties).
Also, add some rows of sample data (as INSERT statements) and the
required output.
See www.aspfaq.com/5006 for more details.
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.
- GROUP BY's on 3 tables in one SELECT?
- Prev by Date: GROUP BY's on 3 tables in one SELECT?
- Next by Date: Re: GROUP BY's on 3 tables in one SELECT?
- Previous by thread: 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
|
|