0
votes

I have to prepare the query from source table to target table. table structure are shown in the image. Can any one help on this.http://i.stack.imgur.com/wnUuZ.png [Tables image]

1

1 Answers

0
votes

Hive's stack function should work here.

SELECT stack(2,
  col1, col2, col3, '',
  col1, col2, '', col4
) AS (newCol1, newCol2, newCol3, newCol4)
FROM source;

Basically, stack generates N rows for each row in the source, and you define each of these new rows.