I have a table defined in Oracle11g schema like this
Txn_summ_dec
=================
id
currentdate
resource_id
user_id
trans_id
eventdescptn
each resource has different event descriptions. I give a date range (of maximum 1 month or less) and resource_id and I want to get distinct count of all users for the given resource id, group by currentdate, eventdescptn
So I have the following query
SELECT COUNT(DISTINCT(txn_summ_dec.user_id)) as dusers, currentDate, eventdescptn
FROM Txn_summ_dec
WHERE resource_id = 1
AND currentdate BETWEEN TO_DATE('2011-12-01', 'YYYY-MM-DD')
AND TO_DATE('2011-12-31', 'YYYY-MM-DD')
GROUP BY currentdate, eventdescptn
and it gives me rightly the result below
dusers currentdate eventdescptn
182 12/01/2011 00:00:00 Save
33 12/04/2011 00:00:00 Save
98 12/01/2011 00:00:00 Read
22 12/30/2011 00:00:00 Write
I want result in the following format:
From the query
with the given date range is suppose 5th to 5th of a month (or less) I want results for all dates in the range for all eventdescptn of a resource. If there is no result for a particular date in the range, for a particular event descptn then it should still have that record in the resultset with a 'dusers' value = 0
so if a resource has 3 different eventdescptns (Save, Read, Write) and the date range is 5th to 30th of a month then there should be a total of 26X3 = 78 records in the resultset..
How do I write a query for that?
Also I will need to convert it to hibernate later.. but Sql to start with is fine
Thanks in advance