Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello i've got problem with selecting data from table..
Source table look like this:
TAB1:
ID,DATE1,DATE_FROM,DATE_TO,TYPE171367,2002-08-05,2002-08-05,2002-11-28,N171366,2002-08-05,2002-11-29,2002-12-31,N171365,2002-08-05,2003-01-01,2003-12-31,N171364,2002-08-05,2004-01-01,2004-02-29,N171363,2002-08-05,2004-03-01,2004-06-30,O172359,2002-08-05,2004-07-01,2005-02-02,N173739,2002-08-05,2005-02-03,2006-10-31,N178377,2002-08-05,2006-11-01,2006-12-31,N178901,2002-08-05,2007-01-01,2007-10-31,N204761,2002-08-05,2007-11-01,2010-04-01,N214343,2002-08-05,2010-04-02,2012-07-31,N220408,2002-08-05,2012-08-01,2015-09-30,N237282,2002-08-05,2015-10-01,2016-03-31,N237283,2002-08-05,2016-04-01,2016-04-30,N244695,2002-08-05,2016-05-01,2016-05-31,N244696,2002-08-05,2016-06-01,2016-09-30,N237284,2002-08-05,2016-10-01,2017-01-31,N248037,2002-08-05,2017-02-01,2017-02-28,N249605,2002-08-05,2017-03-01,2017-09-07,N252105,2002-08-05,2017-09-08,2018-01-31,N255042,2002-08-05,2018-02-01,2018-03-31,N256031,2002-08-05,2018-04-01,2018-06-30,N256032,2002-08-05,2018-07-01,2019-01-31,N262573,2002-08-05,2019-02-01,,N
And a need to select min date_from and max date to while type is the same in time sequence
so destination table should look like that:
TAB2:
ID,DATE1,DATE_FROM,DATE_TO,TYPE171367,2002-08-05,2002-08-05,2004-02-29,N171363,2002-08-05,2004-03-01,2004-06-30,O172359,2002-08-05,2004-07-01,,N
I've try this solution:
TAB1_1:load *,if (isnull(DATE_TO),999999,DATE_TO) as TMP_DATE_TO,"ID"&'#'&"TYPE" as KEY,
RESIDENT TAB1:
NoConcatenatetmp2:LOAD
KEY,
date(MIN(DATE_FROM)) as Min_DATE_FROM,if (max(TMP_DATE_TO)=999999,null(),date(max(TMP_DATE_TO))) as Max_DATE_TOResident TAB1_1Group ByKEY;
Left Join (TAB1_1)LOADKEY,Min_DATE_FROM,Max_DATE_TOResident tmp2;drop table tmp2;
BUT results was:
ID,DATE1,DATE_FROM,DATE_TO,TYPE
172359,2002-08-05,2004-07-01,,N
171363,2002-08-05,2004-03-01,2004-06-30,O
Please help