August 2nd, 2011, 08:46 AM
Select Multiple Date Ranges
I have data such as 'hours', 'date' when and employee worked on the project. What I need is to select the total amount of hours per month of March, April, May, etc...
I know how to select data per single date but wonder how to do it per multiple dates. How does one select total amount of hours per multiple date ranges (March, April...)?
I appreciate your responses.
August 2nd, 2011, 10:24 AM
Did you try adding the hours by month?
Something like this:
TO_CHAR (date_worked, 'Month') "Month",
SUM (hours_worked) Hours_Worked
GROUP BY emp_no, TO_CHAR (date_worked, 'Month')
ORDER BY 1, 2;
Comments on this post
August 2nd, 2011, 10:56 AM
Thanks so much for reply. My issue is not so much to convert date to month.
Here is my data:
POST DATE EMPLOYEE HOURS_WORKED
15-March-2011 Schmidt 7
18-March-2011 Schmidt 2
22-March-2011 Brown 5
12-April-2011 Brown 18
17-April-2011 Patterson 22
7-May-2011 Schmidt 5
9-May-2011 Brown 25
I used statement such as:
select employee, sum(hours_worked) from my_table
where POST_DATE>='1-March-11' AND POST_DATE <= '31-MAR-11'
group by employee
order by employee;
But don't know how to implement in one select statement a querry that will give me sum of hours_worked per employee for post_date = March, then for April, May....etc.
August 2nd, 2011, 12:19 PM
Did you try the query I posted?
August 2nd, 2011, 12:53 PM
Ahhh worked!!! Perfect. Thank you!