Skip to content
Advertisement

Provide an SQL in oracle The conflict column should be yes if same id is found in inc and dec list for each name else the conflict should show no [closed]

Name type   id.  Conflict
Auto inc    1    Yes
Auto inc    2    Yes
Auto inc    3    No
Auto dec    1    Yes
Auto dec    2    Yes 
Auto dec    5    No 
Bus  inc    4    Yes
Bus  dec    4    Yes
Bus  inc    1    Yes
Bus  dec    1    Yes
Bus  inc    7    No
Bus  dec    2    No
Bus  inc    5   Yes
Bus  dec    5   Yes

Advertisement

Answer

You can use the analytical function as follows:

SELECT T.*,
       case when COUNT(CASE WHEN TYPE = 'inc' then 1 end) 
                       over(partition by id, name) > 0 
             and COUNT(CASE WHEN TYPE = 'dec' then 1 end) 
                       over(partition by id, name) > 0
       then 'Y' else 'N' END as conflict
from your_table t
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement