Author |
Topic |
cjonline
Yak Posting Veteran
55 Posts |
Posted - 2011-06-20 : 06:18:38
|
Hi,I have the following table.absences---------Employee Refabsence dateI wish to try and do the following - if the total absence per employee is more than 4 (ie 4 days absence) then set a column named LTS to the number 1, else set the column NONLTS to 1.ie.REF,ABSENCE DATE,LTS,NONLTS---------------------------EMP245, 31/1/2011, 0,1EMP245, 1/2/2011, 0, 1EMP245, 2/2/2011, 0,1EMP245, 3/2/2011, 0,1EMP246, 31/1/2011,1,0EMP246, 31/1/2011, 1,0EMP246, 1/2/2011, 1, 0EMP246, 2/2/2011, 1,0EMP246, 3/2/2011, 1,0note, I'm not updating the absence table, I just need a query to show the results abovethanksCraig. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-06-20 : 06:53:23
|
EMP246 shouldn't have set LTS to 1 because 31/1/2011 is a duplicate value.edit:Also you have not stated if you want to evaluate the data of the whole table or for a specific date range. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
cjonline
Yak Posting Veteran
55 Posts |
Posted - 2011-06-20 : 07:22:11
|
sorry, that was a typo .. I want to evaluate the whole table. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-06-20 : 07:57:56
|
selecta.REF,a.Absence_Date,case when dt.cnt_absence > 4 then 1 else 0 end as LTS,case when dt.cnt_absence <= 4 then 1 else 0 end as NONLTSfrom absence ajoin (select REF,count(*) as cnt_absence from absence group by REF)dton dt.REF = a.REF No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|