Search code examples
sqloracle-databaseoracle-sqldeveloperplsqldeveloper

case in where clause for specific values oracle


we have 2 table, table A and table B,

we are fetch 6 columns in select statement, these are the columns

  1. A.current_value,
  2. A.original_value,
  3. A.current_tax_lot,
  4. B.current_tax,
  5. B.cost_tax,
  6. B.current_tax_cost

now we have to put mathematics condition in query:

  1. A.current_value – B.current_tax is within +/- 2, and

  2. If A.original_value is blank use A.current_tax_lot to perform the formula:

2a. A.current_tax_lot (from above) – B.cost_tax is within +/- 10, or

2b. A.current_tax_lot(from above) – current_tax_cost is within +/-10)


Solution

  • If have not understood a block/calculation, substitute terms / expressions appropriately.

    Select  ...
    Where 
          ABS(NVL(A.current_value, A.current_tax_lot) – B.current_tax) <=2
          AND 
          (
             ABS(A.current_tax_lot – B.cost_tax) <= 10 
             OR
             ABS(A.current_tax_lot – B.current_tax_cost) <= 10
          );