Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Query Question
On 08/10/2006 04:08:01 PM, Hostetter, Jay M wrote:
> I know there has to be a simple way to do this, but my brain can't put
> it togther this afternoon. I have a parent table (accounts) and a child
> table (details). I am creating a view that ties the two tables
> together. I would like a column in this view that shows a summary of a
> column in the parent table - but I want this summary to be for each
> distinct parent record - not the child records.
>
> Here is my view:
>
> create view test_view
> (customer_name,
> amount,
> detail_item)
> as
> (select customer_name,
> sum(amount),
> detail_item
> from accounts a,
> details d
> where a.account_no=d.account_no
> group by customer_name;
>
How about this:
select customer_name,
sum(amount) over (partition by customer_name) as cheating_total,
detail_item
from accounts a,
details d
where a.account_no=d.account_no;
-- Mladen Gogala http://www.mgogala.com -- http://www.freelists.org/webpage/oracle-lReceived on Thu Aug 10 2006 - 20:58:52 CDT
![]() |
![]() |