Skip to content
Advertisement

Duplicate a row based in a column that has 2 values in spark sql

I have a temporary view that looks like this.

ID   Activity
1    Yes           
2    Yes
3    No
4    Yes

What I want is to duplicate a row by adding an ‘All’ value to Activity

Expecting result would be:

ID   Activity
1    Yes           
2    Yes
3    No
4    Yes
1    All
2    All
3    All
4    All

I tried to create it through Zeppelin, but I am not able to update a view.

Is there any way to do it please ?

I can only use SQL unfortunately

Thanks in advance for your help

Advertisement

Answer

You can use union

select Id, Activity
from view

union all

select Id, 'All'
from view
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement