Skip to content
Advertisement

How to convert data into this form in SQL :

Input:

Input

I have to Convert data from input to output. where we trying if for id freq is n then create n rows of that id.

Output:

output

Advertisement

Answer

In Presto, one option uses sequence() and a lateral join to generate the rows:

select t.id, x.value
from mytable t
cross join lateral unnest(sequence(1, t.freq)) as x(value)
order by t.id, x.value
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement