Given these tenancy contracts:
2012 2013 2014 2015 2016
YR | | | | |
FIN_YR | 2012-2013 | 2013-2014 | 2014-2015 | 2015-2016 |
____________________________________________________
1 ----------------++++--------------------------------
2 -----+++++++++++++++++++++++++++++++++++++++--------
4 -----------------------------++++++++++++++++++-----
which lasted over these dates:
TENANCY_ID FROM TO
---------- ---------- ----------
1 2013-05-02 2013-08-12
2 2012-06-22 2015-09-01
4 2014-06-03 2015-11-15
I want to produce a long table like:
TENANCY_ID Financial_Year
---------- --------------
1 2013-2014
2 2012-2013
2 2013-2014
2 2014-2015
2 2015-2016
4 2014-2015
4 2015-2016
where Financial_Year
shows the financial years (1 Apr - 31 Mar) over which each tenancy, at least partly, lasted.
If relevant, db2, otherwise a generic solution would be fine.