Home » SQL & PL/SQL » SQL & PL/SQL » Pls help to write SQL
Pls help to write SQL [message #399989] Fri, 24 April 2009 17:08 Go to next message
liquidcrystal
Messages: 2
Registered: April 2009
Junior Member
HI All,
I got a table with 3 fields account_no, closede_date and balance_amount. And it got data as follows

Acct Closed Balance
No date amount

10 4/1/2009 2345
20 3/2/2009 1009
30 2/1/2009 879
30 4/22/2009 2500
20 1/31/2009 16000
20 4/24/2009 0
10 4/23/2009 0
30 4/24/2009 0
20 4/15/2009 50
20 3/27/2009 18000
20 2/2/2009 111
10 2/27/2009 654
10 4/19/2009 2000

Account is closed when the amount is zero. Following is order by closed _date desc

Acct Closed Balance
No date amount

10 4/23/2009 0
10 4/19/2009 2000

10 4/1/2009 2345
10 2/27/2009 654

20 4/24/2009 0
20 4/15/2009 50

20 3/27/2009 18000
20 3/2/2009 1009
20 2/2/2009 111
20 1/31/2009 16000

30 4/24/2009 0
30 4/22/2009 2500

30 2/1/2009 879

So I want to get is
Account number with closing date and balance amount before closing i.e.

Acct Closed Balance
No date amount

10 4/23/2009 2000
20 4/24/2009 50
30 4/24/2009 2500


Thanks in advance...
Re: Pls help to write SQL [message #399990 is a reply to message #399989] Fri, 24 April 2009 17:25 Go to previous messageGo to next message
BlackSwan
Messages: 25039
Registered: January 2009
Location: SoCal
Senior Member
You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
Please, please, please Read & Follow Posting Guidelines above.
Go to the section labeled "Practice" & do as directed.


Post DDL for tables.
Post DML for test data.

Post expected/desired results.
Re: Pls help to write SQL [message #400015 is a reply to message #399989] Sat, 25 April 2009 00:45 Go to previous message
Michel Cadot
Messages: 64111
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter), use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).

Post a working Test case: create table and insert statements along with the result you want with these data.

Regards
Michel
Previous Topic: Trigger Help
Next Topic: DBMS_SESSION.SET_ROLE error (merged 3)
Goto Forum:
  


Current Time: Mon Dec 05 18:43:29 CST 2016

Total time taken to generate the page: 0.05415 seconds