I want to use with
clause in order to shorten column names which will be used for calculations
with Calc as(
SELECT entries.person_id,
MAX(DECODE(elements.element_name,'Basic Salary',values.screen_entry_value,0))/12 Salary,
MAX(DECODE(elements.element_name,'Mobile Allowance',values.screen_entry_value,0)) Mobile
FROM entries
JOIN values ON values.ELEMENT_ENTRY_ID = entries.ELEMENT_ENTRY_ID
JOIN elements ON elements.ELEMENT_TYPE_ID = entries.ELEMENT_TYPE_ID
JOIN value_types ON value_types.INPUT_VALUE_ID = values.INPUT_VALUE_ID
AND value_types.ELEMENT_TYPE_ID = entries.ELEMENT_TYPE_ID
WHERE elements.language = 'US'
AND elements.element_name IN (
'Mobile Allowance',
'Transportation Allowance',
'Housing Allowance',
'Basic Salary'
)
AND value_types.base_name = 'Amount'
GROUP BY entries.person_id
)
select Salary, Mobile
from persons
JOIN Calc ON Calc.person_id = persons.person_id
whenever I add with
clause block of code to my SQL query it gives error: a column may not be outer-joined to a subquery
, I'm not even using outer join, what's the issue?
Didn't test anything (just corrected the code) - try it like this...