Hi,
I am trying to get the sum of a column for all distinct dates in a month.
Ex: Table A
Fee (number)
lupddt(date)
Output for mon (jan,2003) should look like the below
Sum (Fee) , lupddt
--------------------
10 01-jan-2003
20 02-jan-2003
30 03-jan-2003
10 04-jan-2003
20 05-jan-2003
30 06-jan-2003
10 07-jan-2003
10 08-jan-2003
0 09-jan-2003
---
---
---
10 31-jan-2003
If there was no record inserted on 09-jan-2003 it should still show up in date column and the sum of fees should apper as 0.
I tried doing like this but its taking time and did not get the result as I expected.
SELECT
SUM(FEE), to_char(lupddt,'dd-mon-yyyy')
FROM
A
WHERE
to_char(lupddt,'dd-mon-yyyy') IN (
SELECT TRUNC(to_date('01-JUL-2003','dd-MON-yy'),'MON') + rownum - 1 day
FROM all_objects
WHERE
rownum <= to_char(add_months(TRUNC(to_date('01-JUL-2003','dd-MON-yy'),'MON'),1)-1,'dd')
)GROUP BY to_char(lupddt,'dd-mon-yyyy')
Hope Some one will help me ...
Thank you,
venu
I am trying to get the sum of a column for all distinct dates in a month.
Ex: Table A
Fee (number)
lupddt(date)
Output for mon (jan,2003) should look like the below
Sum (Fee) , lupddt
--------------------
10 01-jan-2003
20 02-jan-2003
30 03-jan-2003
10 04-jan-2003
20 05-jan-2003
30 06-jan-2003
10 07-jan-2003
10 08-jan-2003
0 09-jan-2003
---
---
---
10 31-jan-2003
If there was no record inserted on 09-jan-2003 it should still show up in date column and the sum of fees should apper as 0.
I tried doing like this but its taking time and did not get the result as I expected.
SELECT
SUM(FEE), to_char(lupddt,'dd-mon-yyyy')
FROM
A
WHERE
to_char(lupddt,'dd-mon-yyyy') IN (
SELECT TRUNC(to_date('01-JUL-2003','dd-MON-yy'),'MON') + rownum - 1 day
FROM all_objects
WHERE
rownum <= to_char(add_months(TRUNC(to_date('01-JUL-2003','dd-MON-yy'),'MON'),1)-1,'dd')
)GROUP BY to_char(lupddt,'dd-mon-yyyy')
Hope Some one will help me ...
Thank you,
venu