counting records in a specific time block per day
446181Jun 22 2005 — edited Jun 22 2005I have a scenario where I need to find the number of records in a table called 'DEALS', for a specific time frame (in this case 8am until 9am where the date field stores dates in the following format '06/01/2005 08:23:35'). I need to run this query to include each business day between two dates (ie., june 1, 2005 until current_date).
In addition, this query has to take into account only Users that are ACTIVE in a second table called 'DEALUSERS'
I have worked out the following to get the overall record set, but it is not narrowed down to just the specified time frame, nor does it produce the count for each day's 8:00-9:00 time frame.
SELECT fdls.DEALDATE, user.USERROLE
FROM DEALS dls, DEALUSER user
WHERE dls.CLIENTUSERID = user.USERID
AND user.STATUS = 'ACTIVE'
AND dls.PROXYTRADEFLAG = 'YES'
AND dls.MODENAFLAG = 'YES'
AND TRUNC(dls.DEALDATE)
BETWEEN TO_DATE('06/01/2004 08:00:00', 'MM-DD-YYYY HH:MI:SS')
AND current_date
I tried using the following at the end of the above query, but it doesn't work - any ideas? :confused:
AND TO_CHAR(EXTRACT('HOUR' FROM DEALTS)) = '8'
Can someone help, pls :o