Home » SQL & PL/SQL » SQL & PL/SQL » Need sql querry for this logic
Need sql querry for this logic [message #557206] Mon, 11 June 2012 00:12 Go to next message
ravisap134
Messages: 3
Registered: June 2012
Location: INDIA
Junior Member
Hi,

I have table like this,I need one column for output based on the below logic.

KEY,ACTL_VAL,ETA_VAL,RANGE,DATE_ID,SITE,AREA,UNIT,Month,Year
1111,35,36,50.45,2778,PLANT1,AREA2,SITE1,JAN,2011
1111,40,41,50.45,2783,PLANT1,AREA2,SITE2,FEB,2011
9010,114,37,50.45,2779,PLANT1,AREA2,SITE3,MAR,2011
9010,41,35,50.45,2784,PLANT1,AREA2,SITE1,APR,2011
9011,1500,38,50.45,2789,PLANT2,AREA3,SITE2,MAY,2011
9012,43,37,50.45,2774,PLANT1,AREA1,SITE3,JAN,2011
9012,38,39,50.45,2781,PLANT1,AREA1,SITE4,FEB,2011
9013,39,40,50.45,2782,PLANT1,AREA2,SITE4,MAR,2011

I NEED ONE COLUMN FOR EXAMPLE "MEASURE" WITH THE BELOW LOGIC

If([ETA_VAL]<[ACTL_VAL]) Then (0) Else((([ETA_VAL]-[ACTL_VAL])/(SUM([RANGE])))*100)

Gives The MEASURE value of the respective site/Area/Unit.
Re: Need sql querry for this logic [message #557208 is a reply to message #557206] Mon, 11 June 2012 00:48 Go to previous message
Michel Cadot
Messages: 54219
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Have a look at CASE.

With any SQL question, Post a working Test case: create table and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Before, Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version, with 4 decimals.

Regards
Michel
Previous Topic: ORA-04020: deadlock detected while trying to lock object
Next Topic: please check this queery im getting identifier error
Goto Forum:
  


Current Time: Thu May 23 13:24:43 CDT 2013

Total time taken to generate the page: 0.90504 seconds