Connecting Tech Pros Worldwide Help | Site Map

display dates in a month

Newbie
 
Join Date: Nov 2008
Posts: 10
#1: May 14 '09
hi,
hope the query is simple, but i donno how to do.
i have some records in a table for the month may 2009 as
no date
---------------------------------------
1 02-may-09
4 10-may-09
13 12-may-09
20 24-may-09

only 4 days in may 09. but i want to display like
date no
-----------------------------------------
01-may-09 0
02-may-09 1
03-may-09 0
.
.
10-may-09 4
11-may-09 0
12-may-09 13
.
.
31-may-09 0

finally i need to display 31 days[all days ]in a month
how to do it in query. creating a view with this is needed for me.
pls help me..

thanks in advance..
muthu
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#2: Jun 29 '09

re: display dates in a month


Try this:

Data in table1:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> SELECT * FROM table1;
  3.  
  4. 29-JUN-09    1
  5. 30-JUN-09    2
  6. 01-JUL-09    3
  7. 02-JUL-09    4
  8.  
  9. SQL> SELECT dt,no FROM
  10. (SELECT dt,NVL(rn,0) no FROM
  11. (select TRUNC(SYSDATE,'RRRR') + rn - 1 dt FROM
  12. (SELECT rownum rn from all_objects where rownum <= DECODE(MOD(TO_CHAR(SYSDATE,'RRRR'),4),0,366,365))) x,
  13. table1
  14. WHERE TO_CHAR(x.dt,'DD-MON-RRRR') = (TO_CHAR(y.dat(+),'DD-MON-RRRR'))
  15. AND TO_CHAR(dt,'MON-RRRR') IN (SELECT DISTINCT TO_CHAR(dat,'MON-RRRR') FROM table1))
  16. ORDER BY dt
  17.  
  18.  
Reply