Skip to content
Advertisement

Adding column based on partition by – Oracle

Table:

Objective is to create a new column Col4 as 1 or 0 based on following:

Within each partition by with Col2 and Col3,
either

  1. if Col1-1 does not exists (or)
  2. if Col1-1 (and) Col1-2 both values exists in table,
    then Col4 is 1, else 0.

Output Table:

Advertisement

Answer

If I am following the logic you describe:

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement