sql - Increment all Employees Experience by 1, using month-day from date in postgreSQL -


we've employee's doj(date of join) , need increment employee's experience "1". we've consider "sysdate" , "sysdate+7days(week)" condition. whom ever falls in week experience should incremented while considering "month , day" , ignoring year dates.

suppose:- date= 20-08-2015, we've select records 20-08(dd-mm) 26-08(dd-mm) dates ignoring year.

sampledata

the expected result can dummy column experience.

thanks in advance

ok, real beast first meat, tooth pick:

with chk (   select to_timestamp('12-28', 'mm-dd') dt ), doj_doy (   select workername, workerdoj, extract('doy' workerdoj) doy   my_table ), date_tails (   -- mm/dd in year 0   select workername, workerdoj,          (workerdoj - extract('year' workerdoj) * interval '1 year') date0   doj_doy   union   -- add doj in year (year +1)   select workername, workerdoj,          (workerdoj - (extract('year' workerdoj) - 1) * interval '1 year') date0   doj_doy   doy < 8 ) select workername, workerdoj date_tails, chk date0 between dt , dt + interval '6 days';

the whole idea throw away year filtering. done records in first select clause of third cte:

(workerdoj - extract('year' workerdoj) * interval '1 year') date0 

this leaves timestamp value in year 0. result unioned doj in first week of january, when doy < 8, doy having been calculated in doj_doy cte. ensures include january doj's when post-xmas search.

in first cte have specify date of year search on , go. if want current_date or other timestamp value should convert year 0 date well.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -