Home » SQL & PL/SQL » SQL & PL/SQL » Sql query help
Sql query help [message #330752] Tue, 01 July 2008 02:19 Go to next message
Nusrat
Messages: 38
Registered: June 2007
Location: Mumbai(India)
Member
Hi

I need a help in creating a query.
Below is my table

T1
Month--------year--------Amt

Jan---------2008---------10
Feb---------2008---------30
Mar---------2008---------50
Jan---------2007---------5
Feb---------2007---------20
Mar---------2007---------60

without using pl/sql script how can i write the Sql query to do the calculation like this.

value = ((Amt of Jan2008)-(Amt of Jan2007))/(Amt of Jan2007)*100
value=(10-5)/5 * 100=100

output

Month-------------Value
Jan-------------100
Feb-------------50

Thanks in advance
Nusrat
Re: Sql query help [message #330756 is a reply to message #330752] Tue, 01 July 2008 02:26 Go to previous messageGo to next message
Michel Cadot
Messages: 64140
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You can either join the table with itself or use LAG/LEAD functions depending on the data.

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) and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version (4 decimals).

Regards
Michel
Re: Sql query help [message #330979 is a reply to message #330756] Wed, 02 July 2008 00:12 Go to previous message
Nusrat
Messages: 38
Registered: June 2007
Location: Mumbai(India)
Member

Thanks
Previous Topic: Error in displaying data from PL/SQL type
Next Topic: Error in Trigger
Goto Forum:
  


Current Time: Fri Dec 09 06:06:13 CST 2016

Total time taken to generate the page: 0.28653 seconds