PDA

View Full Version : THE SAME COLUMN



Tzarevna
09-12-2014, 04:35 AM
I have a table a1000 with the following fields: 1) date: 09/31/08, 09/31/08, 09/31/08, 09/31/08, 09/31/08; 2) type: 'P', 'P', 'R', 'R', 'P'; 3) amt: 1, 2, 3, 4, 0.5.

The goal is to write the following condition in ORACLE SQL: CASE WHEN $a1000.date = 09/31/08 AND $a1000.type = 'R' THEN SUM($a1000.amt) ELSE CASE WHEN [and here i do not know how to write the code for the following condition in words: " if type = 'P' then subtract amt from the sum of those amt that are 'R'. i.e. for first 'P' it would be (3+4) - 1, for second 'P' (3+4) - 2 and for the third 'P' (3+4) - 0.5.

Could anybody consult me on this ?