Home » SQL & PL/SQL » SQL & PL/SQL » Grouped data on detail record (10g)
Grouped data on detail record [message #617574] Tue, 01 July 2014 18:16 Go to next message
RM33
Messages: 11
Registered: December 2013
Location: New York City
Junior Member

I am using 10g.

Imagine this table:

Customer_ID, Purchase, Purchased_Date.


I need detail information. Select Customer_ID, Puchase, Purchase_Date From Customer_Table.

Then I need the average purchase from the last 6 months. Then I need to subtract Purchase from Avg(Purchase) So the SQL might look something like this:

Select Customer_ID, Puchase, Purchase - Avg(Purchase) as Activity, Purchase_Date From Customer_Table

How do I do this?
Re: Grouped data on detail record [message #617575 is a reply to message #617574] Tue, 01 July 2014 18:22 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and please read http://www.orafaq.com/forum/t/174502/102589/
Re: Grouped data on detail record [message #617583 is a reply to message #617574] Wed, 02 July 2014 01:30 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You have to use an inline view to compute the average.

Re: Grouped data on detail record [message #617587 is a reply to message #617574] Wed, 02 July 2014 01:47 Go to previous message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
If you have what appears to be a complicated problem, build up to it slowly. In this case, I would begin with query that selects all the rows for the last six months. Then a query that averages the price of those rows.
Previous Topic: DBMS_LOB defined in a View - Error: ORA-01031: insufficient privileges
Next Topic: PLS-00435: DML statement without BULK In-BIND cannot be used inside FORALL
Goto Forum:
  


Current Time: Thu Apr 25 14:52:30 CDT 2024