Reputation: 857
I have the below data
Policy_Name IssueYear ExpiryYear
A 2001 2003
B 2003 2006
I need the output like below :
Policy_Name ActiveYear
A 2001
A 2002
A 2003
B 2003
B 2004
B 2005
B 2006
Upvotes: 0
Views: 59
Reputation: 44991
select t.Policy_Name
,t.IssueYear + pe.i as ActiveYear
from mytable t
lateral view posexplode (split (space (ExpiryYear - IssueYear),' ')) pe as i,x
;
+---------------+------------+
| t.policy_name | activeyear |
+---------------+------------+
| A | 2001 |
| A | 2002 |
| A | 2003 |
| B | 2003 |
| B | 2004 |
| B | 2005 |
| B | 2006 |
+---------------+------------+
Upvotes: 3