Re: Query Question

  • From: Mladen Gogala <gogala@xxxxxxxxxxxxx>
  • To: JHostetter@xxxxxxxxxxxxxxxxxxxx
  • Date: Thu, 10 Aug 2006 21:58:52 -0400

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

--
//www.freelists.org/webpage/oracle-l


Other related posts: