php - gaps in employment history -


i have simple employment history database, store entry id, user id, job, start , end date. there may overlapping entries. need establish in given period there no breaks of given timeframe.

so user_id 1 have work history so

marketing - 01/01/2013 19/05/2013 sales - 01/01/2011 01/05/2012 admin - 01/01/2010 31/12/2010 

i store dates unix timestamp. in 3 year history user_id 1 has break of on 6 months between sales job , marketing job. how can flag them can provide entry period.

this problem harder seems, because can have overlaps in employment history. in fact, can have 1 period of employment entirely "inside" another, or overlapping on either end.

what looking enddate has gap start date and isn't in period of employment. so, let's use correlated subquery next start date after end date, in:

     select t.*,              (select startdate               t t2               t2.user_id = t.user_id ,                     t2.startdate > t.enddate               order startdate desc               limit 1              ) nextstartdate       t 

now, question is: period covered period. this, i'll use complicated where clause:

select t.* (select t.*,              (select startdate               t t2               t2.user_id = t.user_id ,                     t2.startdate > t.enddate               order startdate desc               limit 1              ) nextstartdate       t      ) t not exists (select 1                   t t2                   t2.startdate <= t.enddate ,                         t2.enddate >= t.nextstartdate                  ) ,       (t.enddate null or t.enddate > now()) 

depending on how handling overlaps, might want allow few days of lag between dates.

this should return records in table there gaps. in example data, return record today (2013-05-19). "sales" record has gap afterwards until "marketing" position. "marketing" returned in future, because have ended in past.

it possible 1 gap result in multiple records being returned. can happen when there overlaps, explain numbers: (0, 10), (5, 12), (15, 20). gap starting @ 12/13 affect both records. if issue, query can fixed, although first thought on how fix makes query more complicated.

presumably, filtering on userid, can put in outermost where clause.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -