我有
的SQL查询startdate 23/09/2013
enddate 06/10/2013
days_absent 14
我需要在9月7日和10月7日显示数据透视表中的日期 而不是9月14日
Month Days_Absent
------------------------
SEP 7
OCT 7
以下是填充报告的查询:
SELECT TO_CHAR(ACCINJ_VIEW.STARTDATEOFABSENCE,'DD/MM/YYYY') AS "Start Date of Absence" ,
TO_CHAR(ACCINJ_VIEW.ENDDATEOFABSENCE,'DD/MM/YYYY') AS "End Date of Absence" , ACCINJ_VIEW.DAYSABSENT AS "Days Absent" ,
FROM ACCINJ_VIEW ACCINJ_VIEW,
WHERE ACCINJ_VIEW.IDPERSONUNIQUEKEY = INJG_VIEW.IPERSONUNIQUEKEY(+) AND ov_VIEW.ACCDATE BETWEEN :ACCDATESTART AND :ACCDATEEND
我认为这可能有效
WITH all_days AS
(
SELECT first_day + LEVEL - 1 AS a_day
FROM (
SELECT TO_DATE ( '05/08/2011' , 'DD/MM/YYYY') AS first_day, -- Start Date
TO_DATE ( '16/10/2011' , 'DD/MM/YYYY') AS last_day -- End Date
FROM dual
)
CONNECT BY LEVEL <= last_day + 1 - first_day
)
SELECT TO_CHAR (TRUNC(a_day,'MONTH'),'FMMonth YYYY') AS month,
COUNT (*) AS day
FROM all_days
GROUP BY TRUNC (a_day, 'MONTH')
ORDER BY TRUNC (a_day, 'MONTH')
/
结果:
MONTH DAY
-------------- ----------
August 2011 27
September 2011 30
October 2011 16