sqllearner
Aged Yak Warrior
639 Posts |
Posted - 2011-06-25 : 19:00:13
|
create table EMP_INFO(EMP_NUMBER varchar(13), COMPANY varchar(10), AGREE_START_DT datetime, PROCESS_TYPE varchar(10), STATUS_CODE varchar(10)) INSERT INTO EMP_INFOSELECT '899','Y2C' ,'2/15/2010','MP','SA' UNION ALLSELECT '899','Y2C' ,'7/27/2010','MP','FE' UNION ALLSELECT '65421','YELLO' ,'2/15/2010','CP','SA' UNION ALLSELECT '65421','YELLO' ,'4/30/2010','CP','TT' UNION ALLSELECT '65421','YELLO' ,'5/30/2010','CP','TD' UNION ALLSELECT '65421','YELLO' ,'6/19/2010','MP','MA' UNION ALLSELECT '65421','YELLO' ,'6/21/2010','CP','FE' UNION ALLSELECT '65421','YELLO' ,'6/28/2010','PF','MA' UNION ALLSELECT '65421','YELLO' ,'11/20/2010','CP','FE'-------------------------------------------------------Tried grouping to get a result like '899','Y2C' ,'2/15/2010','MP','SA' '65421','YELLO' ,'2/15/2010','CP','SA''65421','YELLO' ,'6/19/2010','MP','MA''65421','YELLO' ,'6/21/2010','CP','FE''65421','YELLO' ,'6/28/2010','PF','MA''65421','YELLO' ,'11/20/2010','CP','FE'Grouping logic is like :group by EMP_NUMBER and COMPANY and want the minimum value of AGREE_START_DT based on the PROCESS_TYPEThe challenge is when we group we should get the consecutive row values with same EMP_NUMBER and COMPANY based on the date and if the consecutive rows have the same PROCESS_TYPE then we need to get only the minimum row with the AGREE_START_DT but if the consecutive rows differs in the PROCESS_TYPE then you can't group them. |
|