-
Complex Grouping in Oracle
Hi
I have two tables, ACCOUNTS and GROUPS. ACCOUNTS table store account level information with amount. And one person can have multiple accounts. GROUPS table store the account group information. One group can have multiple accounts of the sam person.
Account Table
ActNo, Name, Amount, ActName
11111, JEFF, 100.00, Funds
11112, JEFF, 200.00, Funds
11113, JEFF, 200.00, Funds
11114, ANNA, 120.00, Sal
11115, GARY, 232.00, Sal
11116, GARY, 122.00, Sal
Group Table
GrpId, ActNo
100 , 11111
100 , 11112
100 , 11113
101 , 11114
102 , 11115
102 , 11116
I want to get an output to show the total amount for each group with latest/maximum account information. For Example:
GrpID, ActNo, Name, TotAmnt, ActName
100 , 11113, JEFF, 500.00 , Funds
101 , 11114, ANNA, 120.00 , Sal
102 , 11116, GARY, 354.00 , Sal
I am not sure how to create a single single oracle query. Please help. Thanks in advance.
-
-Divide and Conquer works a lot in SQL-
Hi there,
Maybe part of the solution you are looking for is close to:
(You need to create a #t1 temp table fot this)
insert into #t1
select g.grpid gruoup_id, sum(a.amount) total_amount, max(a.amount) maximum_amount
from groups g, account a
where a.accountno = g.accountno
group by g.grpid
This will give you group id, total amount and maximum amount.
You still require acctno, funds and acctname, so I will put this last sql statement in a temp table, that could be called #t1, and later
select t.group_id a.acctno, a.acctname, t.total_amount, a.funds
from #t1 t, account a
where a.acctno = t.acctno
I hope this gives you an idea on how to accomplish what you are looking for.
Tonci Korsano
Similar Threads
-
By kylemcna in forum ASP.NET
Replies: 5
Last Post: 04-13-2007, 02:23 AM
-
Replies: 3
Last Post: 08-01-2005, 05:59 AM
-
By Eugene Chernyak in forum Enterprise
Replies: 0
Last Post: 07-27-2000, 09:35 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks