SELECT date1, To_Char(date1,'DY'), date2, To_Char(date2,'DY'), Trunc(date2-date1) Days
FROM Table_Name WHERE Trunc(date2-date1) > 0
这给了我那些日差超过1天的记录。现在,我必须知道假期或星期六是否在这两个日期之间。如果确实如此,那么我必须将它从“天差”中排除并显示结果。
DATE 1 DAY1 DATE2 DAY2 DAY DIFFERENCE
19-MAY-12 SAT 21-MAY-12 MON 2
18-MAY-12 FRI 21-MAY-12 MON 3
18-MAY-12 FRI 21-MAY-12 MON 3
18-MAY-12 FRI 22-MAY-12 TUE 3
18-MAY-12 FRI 22-MAY-12 TUE 3
18-MAY-12 FRI 22-MAY-12 TUE 3
05-JUN-12 TUE 07-JUN-12 THU 2
05-JUN-12 TUE 07-JUN-12 THU 2
我试过这个,但有几个故障。我正在研究它们。
SELECT transaction_date, TO_CHAR(transaction_date,'DY'), deposit_date, TO_CHAR(deposit_date,'DY'), trunc(deposit_date - transaction_date + 1) Total_Days,
trunc(deposit_date - transaction_date) -
(CASE
WHEN TO_CHAR(date1, 'DY') IN ('SAT')
OR date1 IN ('25-JAN-13', '27-MAR-13', '29-MAR-13', '01-APR-13', '24-APR-13', '09-AUG-13', '15-AUG-13', '30-SEP-13', '02-OCT-13'
, '13-OCT-13', '16-OCT-13', '03-NOV-13', '14-NOV-13', '17-NOV-13', '25-DEC-13')
THEN 1
WHEN TO_CHAR(date1, 'DY') NOT IN ('SAT')
THEN 0
END
+
CASE
WHEN TO_CHAR(date2, 'DY') IN ('SUN', 'SAT')
OR deposit_date IN ('25-JAN-13', '27-MAR-13', '29-MAR-13', '01-APR-13', '24-APR-13', '09-AUG-13', '15-AUG-13', '30-SEP-13', '02-OCT-13'
, '13-OCT-13', '16-OCT-13', '03-NOV-13', '14-NOV-13', '17-NOV-13', '25-DEC-13') THEN 1
ELSE 0
END
) BUSINESSDAYS
FROM Table_Name
DATE 1 DAY1 DATE2 DAY2 WORKING DAYS
19-MAY-12 SAT 21-MAY-12 MON 1
18-MAY-12 FRI 21-MAY-12 MON 3
18-MAY-12 FRI 21-MAY-12 MON 3
18-MAY-12 FRI 22-MAY-12 TUE 3
18-MAY-12 FRI 22-MAY-12 TUE 3
18-MAY-12 FRI 22-MAY-12 TUE 3
18-MAY-12 FRI 19-MAY-12 SAT 1