Dette vil finde hver bruger, der har overskredet orlovsbeløbet for hver type orlov:
Oracle 11g R2 Schema Setup :
OPRET TABEL Medarbejder24( MEDARBEJDER-ID, JOBROLER ) ASSELECT 1, 'RoleA' FRA DUAL UNION ALLSELECT 2, 'RoleB' FRA DUAL UNION ALLSELECT 3, 'RoleB' FRA DUAL;OPRET TABELFRA 25( ANSATSID, ANSAT , STARTDATO, ENDDATE) ASSELECT 1,1,'SickLeave', DATE '2018-01-01', DATE '2018-01-11' FROM DUAL UNION ALLSELECT 1,2,'SickLeave', DATE '2018-01-21' ', DATO '2018-01-31' FRA DUAL UNION ALLSELECT 1,3,'EarnedLeave',DATO '2018-01-11', DATO '2018-01-21' FRA DUAL UNION ALLSELECT 1,4,'EarnedLeave' ,DATO '2018-02-01', DATO '2018-02-11' FRA DUAL UNION ALLSELECT 1,5,'EarnedLeave',DATO '2018-02-21', DATO '2018-03-03' FRA DUAL UNION ALLSELECT 2,6,'EarnedLeave',DATE '2018-02-01', DATO '2018-02-13' FRA DUAL UNION ALLSELECT 3,7,'SickLeave', DATO '2018-01-01', DATO '2018 -01-09' FRA DUAL;CREATE TABLE JOBROLESELIGIBLE(JOBROLES, ELIGIBLE_SICK_LEAVES, ELIGIBLE_EARNED_LEAVES) ASSELECT 'RoleA', 14, 24 FROM DUAL UNION ALLSELECTROM 'RoleB', 7,DUAL>Fcode>
Forespørgsel 1 :
SELECT e.employeeId, l.leavetype, l.days_leave, r.AllowedLeaveAmountFROM Employee24 e INNER JOIN ( SELECT medarbejderId, SUM( slutdato - startdato ) AS days_leave, orlovstype FROM Orlov25 GRUPPE EFTER ansatId, orlovstype ) l TYPE ( e.employeeId =l.employeeId ) INNER JOIN ( SELECT * FROM JobRolesEligibleLE UNPIVOT ( AllowedLeaveAmount FOR LeaveType IN ( Eligible_Sick_Leaves AS 'SickLeave', Eligible_Earned_Leaves AS 'EarnedLeave)OG .leave ON type.leaveON. jobroles =r.jobroles )WHERE l.days_leave> r.AllowedLeaveAmount
| MEDARBEJDER | LEAVETYPE | DAYS_LEAVE | TILLADET LEVERINGSMÆLDE ||----------------|------------------|------------|------------- ------------|| 1 | Sygemelding | 20 | 14 || 1 | EarnedLeave | 30 | 24 || 2 | EarnedLeave | 12 | 10 || 3 | Sygemelding | 8 | 7 |