我通过分组日期从我的表中获得总数。例如,当我尝试获得'08 .03.2013'和'22 .03.2013'之间的值时,请查看下面的图片。没有关于18.03.2013和20.03.2013的数据。
但我需要那个日期,因为我在前端使用高图,而不想在前端处理这个。
你有什么建议吗?
由于
SELECT TO_CHAR(CR_DATE, 'DD') DAY, TO_CHAR(CR_DATE, 'MM') MONTH, TO_CHAR(CR_DATE, 'YY') YEAR,
count(STAB_ID) AS total FROM paytrans
WHERE acct_id = 1552 AND status = 'DND_FNSH' and CR_DATE > '08.03.2013' AND CR_DATE < '22.03.2013'
GROUP BY TO_CHAR(CR_DATE, 'YY'), TO_CHAR(CR_DATE, 'DD'), TO_CHAR(CR_DATE, 'MM')
ORDER BY year, month, day
[编辑@art]
SELECT TO_CHAR(CR_DATE-1, 'DD') + LEVEL DAY, TO_CHAR(CR_DATE, 'MM') MONTH, TO_CHAR(CR_DATE, 'YY') YEAR,(cr_date-1) + LEVEL AS cr_date
FROM
(
SELECT
To_Date('08.05.2013', 'DD.MM.YYYY') end_date,
To_Date('08.04.2013', 'DD.MM.YYYY') cr_date
FROM dual
)
CONNECT BY LEVEL <= (end_date - cr_date)+1
答案 0 :(得分:1)
根据您的日期,这是日历。您可以在查询中比较日期和日历日期:
SELECT cr_date
, to_char(cr_date, 'DD') curr_day
, to_char(cr_date, 'MM') curr_month
, to_char(cr_date, 'YYYY') curr_year
FROM
(
SELECT (cr_date-1) + LEVEL AS cr_date
FROM
(
SELECT To_Date('08.05.2013', 'DD.MM.YYYY') end_date
, To_Date('08.04.2013', 'DD.MM.YYYY') cr_date
FROM dual
)
CONNECT BY LEVEL <= (end_date - cr_date)+1
)
/
CR_DATE CURR_DAY CURR_MONTH CURR_YEAR
-------------------------------------------------
4/8/2013 08 04 2013
4/9/2013 09 04 2013
4/10/2013 10 04 2013
....
....
4/30/2013 30 04 2013
5/1/2013 01 05 2013
5/2/2013 02 05 2013
...
...
5/8/2013 08 05 2013